use wxXmlResource as an XML parser ?

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
User avatar
baert
I live to help wx-kind
I live to help wx-kind
Posts: 169
Joined: Wed Sep 15, 2004 1:52 pm
Location: France - Compiegne-Paris-Lille

use wxXmlResource as an XML parser ?

Post by baert »

Hi,
I just need a small xml parser in my app,

I saw the wxXmlDocument class, but the advice is not to use it.

I heard about the possibility to use wxXmlResource as an XML parser,
but In its functions, I can't find the things I need to extract nodes, attributes, etc...

Have you any hint or exemples using wxXmlResource or wxXmlDocument for parsing simple xml doc ?

Thanks for your help !

Bart
Bart
benedicte
wxWorld Domination!
wxWorld Domination!
Posts: 1409
Joined: Wed Jan 19, 2005 3:44 pm
Location: Paris, France

Post by benedicte »

I don't think the XML parser for resources can be used for something else than loading resources...

You should have a look at wxXML2 (http://wxcode.sourceforge.net/components/wxxml2/).
priyank_bolia
wxWorld Domination!
wxWorld Domination!
Posts: 1339
Joined: Wed Aug 03, 2005 8:10 am
Location: BANGALORE, INDIA
Contact:

Post by priyank_bolia »

In the previous threads I heard of http://www.grinninglizard.com/tinyxml/ as an alternative, though I am still looking for the best one. Very confusing issue like which editor to use.
ssigala
Earned some good credits
Earned some good credits
Posts: 109
Joined: Fri Sep 03, 2004 9:30 am
Location: Brescia, Italy

Re: use wxXmlResource as an XML parser ?

Post by ssigala »

baert wrote:Hi,
I just need a small xml parser in my app,
I strongly suggest TinyXML. It it very small, well documented and very well written (you can customize it after 5 minutes of reading the code).
Sandro Sigala - Kynosoft, Brescia
hongxing
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 227
Joined: Mon Aug 01, 2005 10:04 am

I recommend xerces-c

Post by hongxing »

I compared tinyxml,xerces-c,libxml,wxxml2,expat
tinyxml is good, but it can not support Unicode.
libxml is difficult to compile.
xerces-c is used and supported by many company and community, so it is
suitable for my project.
Chr
Earned some good credits
Earned some good credits
Posts: 115
Joined: Tue May 31, 2005 2:17 pm

Post by Chr »

mmh, look at the license too!
If you make a commercial app a more liberal license is good (not the GPL)
wxWidgets is nice
netsuvi
In need of some credit
In need of some credit
Posts: 7
Joined: Fri Jan 13, 2006 2:06 pm

Post by netsuvi »

I have to port some java lines to C++ (wxwidgets library if possible)
Can someone give me a tip on this ? What is the best way to port this.
What XMLParser should I use?

// import org.w3c.dom.*; and import java.xml.parser";
try {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document document = builder.parse(urlString);
NodeList nodes = document.getElementsByTagName("RecommendedURL");
Node n = nodes.item(0);
while(n.getNodeType() != Node.TEXT_NODE) {
n=n.getFirstChild();
}
return n.getNodeValue();
} catch (SAXException sxe) {
// Error generated during parsing)
System.out.println("SAXException getRecommendedServer()");
sxe.printStackTrace();
} catch (ParserConfigurationException pce) {
// Parser with specified options can't be built
System.out.println("ParserException getRecommendedServer()");
pce.printStackTrace();
} catch (IOException ioe) {
// I/O error
System.out.println("IOExceptiongetRecommendedServer()");
ioe.printStackTrace();
} */
Sof_T
Can't get richer than this
Can't get richer than this
Posts: 864
Joined: Thu Jul 28, 2005 9:48 pm
Location: New Forest, United Kingdom
Contact:

Post by Sof_T »

I personally use wxXML since it is included with the distribution. I find it extremely easy to use for basic xml, it doesn't support some features like preserving comments.

The header contains the following warning
CAUTION! *
* *
* The API defined in this header *WILL* change in the future and backward *
* compatibility will *not* be preserved. If you use these classes in your *
* application, it probably won't compile with future wxWidgets releases. *
* Use on your own risk.
but since the file is dated year 2000 and it is still there I guess there is no problem to continue to use it until it is replaced. If you need example code I can provide some.
netsuvi
In need of some credit
In need of some credit
Posts: 7
Joined: Fri Jan 13, 2006 2:06 pm

Post by netsuvi »

Hi. Examples would be great. Can you post a link for downloading?
toxicBunny
Super wx Problem Solver
Super wx Problem Solver
Posts: 424
Joined: Tue Jul 12, 2005 8:44 pm
Location: Alabama, USA

Post by toxicBunny »

I've also started using the wxXml classes for my XML parsing. Since they are used by the XRC classes, and more recently the new rich text classes, I doubt they'll be changing drastically in the near future. If it changes in a future release, I can always change my parsing code when I upgrade.

I made versions of a class using TinyXML, wxXml, and wxXml2 as a test. The code for all three was fairly similar and easy to convert between them. TinyXML requires a little work to convert strings and doesn't support unicode as previously mentioned. wxXml2 adds validation support for XML using a DTD, but it also adds dependencies on libxml2 (and libiconv under Windows).

Since the wxXml classes are already included in the wxWidgets release, I don't see any reason not to use them. There are some convenience functions that could be added, but the basic functionality is already there.

You can look at the XRC source files for some examples, or I could post some of the code I use for parsing the report writer XML files.

-Scott
wxMSW 2.6.2, VS 2002, 2003 and 2005, Code::Blocks and mingw, Windows XP Pro
Sof_T
Can't get richer than this
Can't get richer than this
Posts: 864
Joined: Thu Jul 28, 2005 9:48 pm
Location: New Forest, United Kingdom
Contact:

Post by Sof_T »

I've also started using the wxXml classes for my XML parsing. Since they are used by the XRC classes, and more recently the new rich text classes, I doubt they'll be changing drastically in the near future. If it changes in a future release, I can always change my parsing code when I upgrade.
I agree with ToxicBunny's feelings here. Use what is available and if it changes in the future well it will be necessary to make some small changes to your existing code.

It would be nice to know the future of wxXml (anyone?). A few enhancements to the existing framework would be nice if no major changes are planned for the future.

The following is my code for loading an xml document and parsing it for the needed information. (I load from a zip file hence the name).

Code: Select all

             wxXmlDocument XMLDocument(ZipInputStream);
             if(XMLDocument.IsOk())
             {
                 wxXmlNode * RootNode = XMLDocument.GetRoot();
                 //Set the widgets name
                 TempWidget->SetName(RootNode->GetName());
                 wxXmlProperty * PropertyList = RootNode->GetProperties();
                 do
                 {
                     //Get the name of the current XML property
                     wxString PropertyName = PropertyList->GetName();
                     if(PropertyName.CmpNoCase("type")==0)
                     {
                         //Get the type of the base widget
                         TempWidget->SetType(PropertyList->GetValue());
                     }
                     else if(PropertyName.CmpNoCase("palette")==0 || PropertyName.CmpNoCase("pallete")==0)
                     {
                         //Get the palette the widget belongs on
                         Palette = PropertyList->GetValue();
                     }
                     //Disregard the icon name has no relevance
                     /*else if(PropertyName.CmpNoCase("icon")==0)
                     {
                         EdtIconName->SetValue(PropertyList->GetValue());
                     }*/
                     else if(PropertyName.CmpNoCase("mediaplayer")==0)
                     {
                         //Get the media player type this widget is for
                         MediaPlayer = PropertyList->GetValue();
                     }
                     else if(PropertyName.CmpNoCase("version")==0)
                     {
                         //Get the version of the media player this widget is for
                         MediaVersion = PropertyList->GetValue();
                     }
                     else if(PropertyName.CmpNoCase("os")==0)
                     {
                         //Get the operating system the media player runs on
                         OS = PropertyList->GetValue();
                     }
                     else if(PropertyName.CmpNoCase("tooltip")==0)
                     {
                         //Get the tooltip for the palette button
                         Tooltip = PropertyList->GetValue();
                     }
                     PropertyList = PropertyList->GetNext();
                 }while(PropertyList);
     
                 //Get the list of the attributes and methods for this widget
                 wxXmlNode * ChildrenNodes = RootNode->GetChildren();
     
                 do
                 {
                     wxString NodeType = ChildrenNodes->GetName();
                     //Get attribute values and add to Temp widget
                     if(NodeType.CmpNoCase("ATTRIBUTE")==0)
                     {
                         wxString TempName = ChildrenNodes->GetPropVal(_T("name"),_T(""));
                         wxString TempType = ChildrenNodes->GetPropVal(_T("valuetype"),_T(""));
                         wxString TempDefault = ChildrenNodes->GetPropVal(_T("defaultvalue"),_T(""));
                         wxString TempDesign = ChildrenNodes->GetPropVal(_T("design"),_T(""));
                         wxString TempRun = ChildrenNodes->GetPropVal(_T("run"),_T(""));
                         TempWidget->AddAttribute(TempName,TempType,TempDefault,TempDesign,TempRun);
                     }
                     //Get events and methods for the widget and add them on
                     else if(NodeType.CmpNoCase("METHOD")==0)
                     {
                         wxString TempName = ChildrenNodes->GetPropVal(_T("name"),_T(""));
                         wxString TempType = ChildrenNodes->GetPropVal(_T("methodtype"),_T(""));
                         wxString TempParameters = ChildrenNodes->GetPropVal(_T("parameterlist"),_T(""));
                         wxString TempDefault = ChildrenNodes->GetPropVal(_T("defaultvalue"),_T(""));
                         if(TempType.CmpNoCase(wxT("Event")))
                         {
                             SkinDocWidgetEvent * TempEvent = new SkinDocWidgetEvent();
                             TempEvent->SetName(TempName);
                             TempEvent->SetParameterList(TempParameters);
                             TempEvent->SetDefault(TempDefault);
                             //Add to the event list
                             TempWidget->AddEvent(TempEvent);
                         }
                         else
                         {
                             SkinDocWidgetMethod * TempMethod = new SkinDocWidgetMethod();
                             TempMethod->SetName(TempName);
                             TempMethod->SetParameterList(TempParameters);
                             TempMethod->SetDefault(TempDefault);
                             //Add to the method list
                             TempWidget->AddMethod(TempMethod);
                         }
                     }
                     ChildrenNodes = ChildrenNodes->GetNext();
                 }while(ChildrenNodes);
             }
         }
I hope this helps.

Sof.T
netsuvi
In need of some credit
In need of some credit
Posts: 7
Joined: Fri Jan 13, 2006 2:06 pm

linker error

Post by netsuvi »

It compiles but I get a linker error:

Linking...
HTConnector.obj : error LNK2019: unresolved external symbol "public: __thiscall wxXmlDocument::wxXmlDocument(void)" (??0wxXmlDocument@@QAE@XZ) referenced in function "public: __thiscall HTConnector::HTConnector(void)" (??0HTConnector@@QAE@XZ)
HTConnector.obj : error LNK2019: unresolved external symbol "public: __thiscall wxXmlNode::~wxXmlNode(void)" (??1wxXmlNode@@QAE@XZ) referenced in function "public: void * __thiscall wxXmlNode::`scalar deleting destructor'(unsigned int)" (??_GwxXmlNode@@QAEPAXI@Z)
HTConnector.obj : error LNK2019: unresolved external symbol "public: class wxXmlDocument & __thiscall wxXmlDocument::operator=(class wxXmlDocument const &)" (??4wxXmlDocument@@QAEAAV0@ABV0@@Z) referenced in function "public: class wxString __thiscall HTConnector::getRecommendedServer(void)" (?getRecommendedServer@HTConnector@@QAE?AVwxString@@XZ)
HTConnector.obj : error LNK2019: unresolved external symbol "public: __thiscall wxXmlDocument::wxXmlDocument(class wxInputStream &,class wxString const &)" (??0wxXmlDocument@@QAE@AAVwxInputStream@@ABVwxString@@@Z) referenced in function "public: class wxString __thiscall HTConnector::getRecommendedServer(void)" (?getRecommendedServer@HTConnector@@QAE?AVwxString@@XZ)
vc_mswd\htconnect.exe : fatal error LNK1120: 4 unresolved externals

Can someone help me to solve this?
benedicte
wxWorld Domination!
wxWorld Domination!
Posts: 1409
Joined: Wed Jan 19, 2005 3:44 pm
Location: Paris, France

Post by benedicte »

which wx libs are you linking your app with ?
netsuvi
In need of some credit
In need of some credit
Posts: 7
Joined: Fri Jan 13, 2006 2:06 pm

Post by netsuvi »

I am using VC8 and I have input dependencies to

wxmsw26d_core.lib
wxbase26d_net.lib
wxbase26d.lib
wxtiffd.lib
wxjpegd.lib
wxpngd.lib
wxzlibd.lib
wxregexd.lib
wxexpatd.lib
winmm.lib
comctl32.lib
rpcrt4.lib
wsock32.lib
oleacc.lib
odbc32.lib

am I missing somtehing? Everthing else links, just not xml.h/xml.cpp
benedicte
wxWorld Domination!
wxWorld Domination!
Posts: 1409
Joined: Wed Jan 19, 2005 3:44 pm
Location: Paris, France

Post by benedicte »

The XRC sample uses:
  • wxmsw26ud_xrc.lib
    wxmsw26ud_html.lib
    wxmsw26ud_adv.lib
    wxmsw26ud_core.lib
    wxbase26ud_xml.lib
    wxbase26ud.lib
    wxtiffd.lib
    wxjpegd.lib
    wxpngd.lib
    wxzlibd.lib
    wxregexud.lib
    wxexpatd.lib
    kernel32.lib
    user32.lib
    gdi32.lib
    comdlg32.lib
    winspool.lib
    winmm.lib
    shell32.lib
    comctl32.lib
    ole32.lib
    oleaut32.lib
    uuid.lib
    rpcrt4.lib
    advapi32.lib
    wsock32.lib
    oleacc.lib
    odbc32.lib
As XRC uses the XML parser, you may need some of the libs listed here.
Post Reply