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 » Tue Sep 13, 2005 7:44 am

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 » Tue Sep 13, 2005 7:52 am

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 » Tue Sep 13, 2005 8:01 am

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 » Tue Sep 13, 2005 1:22 pm

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 » Tue Sep 13, 2005 1:57 pm

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 » Tue Sep 13, 2005 7:06 pm

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 » Fri Jan 13, 2006 2:12 pm

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 » Fri Jan 13, 2006 2:39 pm

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 » Fri Jan 13, 2006 4:12 pm

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 » Fri Jan 13, 2006 4:38 pm

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 » Fri Jan 13, 2006 5:34 pm

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 » Tue Feb 07, 2006 9:14 am

It compiles but I get a linker error:

Linking...
HTConnector.obj : error LNK2019: unresolved external symbol "public: __thiscall wxXmlDocument::wxXmlDocument(void)" ([email protected]@[email protected]) referenced in function "public: __thiscall HTConnector::HTConnector(void)" ([email protected]@[email protected])
HTConnector.obj : error LNK2019: unresolved external symbol "public: __thiscall wxXmlNode::~wxXmlNode(void)" ([email protected]@[email protected]) referenced in function "public: void * __thiscall wxXmlNode::`scalar deleting destructor'(unsigned int)" ([email protected]@[email protected])
HTConnector.obj : error LNK2019: unresolved external symbol "public: class wxXmlDocument & __thiscall wxXmlDocument::operator=(class wxXmlDocument const &)" ([email protected]@[email protected]@@Z) referenced in function "public: class wxString __thiscall HTConnector::getRecommendedServer(void)" ([email protected]@@[email protected]@XZ)
HTConnector.obj : error LNK2019: unresolved external symbol "public: __thiscall wxXmlDocument::wxXmlDocument(class wxInputStream &,class wxString const &)" ([email protected]@[email protected]@@[email protected]@@Z) referenced in function "public: class wxString __thiscall HTConnector::getRecommendedServer(void)" ([email protected]@@[email protected]@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 » Tue Feb 07, 2006 9:41 am

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 » Tue Feb 07, 2006 9:52 am

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 » Tue Feb 07, 2006 10:26 am

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