Using XML With WxWidgets
From WxWiki
Currently, the developers of wxWidgets have chosen not to implement an 'official' XML parser into wxWidgets, leaving the user free to choose the one that fits his purposes best. There are several possibilities (all the following are cross-platform):
One possibility is to use TinyXML. TinyXML can be easily used along with wxWidgets. It is small and has a relatively easy learning curve. There is a guide on How To Use TinyXML With WxWidgets.
Alternately, Francesco Montorsi wrote a set of wrapper classes for the libxml2 library, which is a well-known cross-platform open source XML parsing library (it also supports various compilers). The wrappers are called wxxml2 and are hosted at http://wxcode.sourceforge.net/components/wxxml2.
Documentation on both of these can be found by following the links.
[edit] Using wxWidget's built-in XML parsers
Although wxWidgets does not have an official XML parser, some of its components have built-in parsers which may be used to parse other XML files:
- wxWidget's XRC uses an XML parser that can be used to parse other files.
- WxArt2d has an XML pull parsing system which can be extracted from wxArt2D
Note: documentation on using either of these two methods is scarce. Post to the mailing lists if you need help, or just use one of the ways mentioned earlier.
[edit] Additional notes
A project is underway to write some proper xml stuff for wxWidgets at [1] ((at this moment, the page is down) Seems to be back, but old (2002 ?) ? Caeies).
Yuri notes:
Well I do use wxXml to read/write some configs. IMHO while it is OK for that job there are some things it could be better:
- escaping special symbols when writing properties/text (it reads escaped stuff back OK btw)
- better ways to access/traverse xml tree
- some ways to move data between trees other than copying/deleting.
So overall impression: OK for simple stuff, but for really complex transformations I would use something more appropriate.
Just another XML thing is available at [2]. This project was designed for XMPP/Jabber usage that rquires a XML socket tcp stream. There is a stream reader implementation for expat (that is included in wx anyway) that generates a DOM. Therefore there is also a minimal 'easy to use' DOM c++ implementation for XML in sourcforge's cvs: filename xs_xml.h. Sample of DOM's usage in c++:
/**********************************************************
How do you use this dom?
Nothing easier then this:
xsNode *root, *child, *text;
xsString strDump;
root = new xsNode(0, // no parent
NODE_ELEMENT,
xT("theRoot"));
child = new xsNode(root, // parent
NODE_ELEMENT,
xT("theChild"));
new xsProperty(child, xT("xmlns"), xT("http://thenamesspace.com"));
text = new xsNode(root, // parent
NODE_TEXT,
xT("some text :P"));
xsNodeDump(root, strDump);
// delete a node with all children and properties
delete child;
// delete all
delete root;
**********************************************************/
