Mbed port of the Simple Plain Xml parser. See http://code.google.com/p/spxml/ for more details. This library uses less memory and is much better suited to streaming data than TinyXML (doesn\'t use as much C++ features, and especially works without streams). See http://mbed.org/users/hlipka/notebook/xml-parsing/ for usage examples.

Dependents:   spxmltest_weather VFD_fontx2_weather weather_LCD_display News_LCD_display ... more

Committer:
hlipka
Date:
Wed Nov 24 20:52:14 2010 +0000
Revision:
0:3fa97f2c0505
initial revision

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hlipka 0:3fa97f2c0505 1 /*
hlipka 0:3fa97f2c0505 2 * Copyright 2008 Stephen Liu
hlipka 0:3fa97f2c0505 3 * LGPL, see http://code.google.com/p/spxml/
hlipka 0:3fa97f2c0505 4 * For license terms, see the file COPYING along with this library.
hlipka 0:3fa97f2c0505 5 */
hlipka 0:3fa97f2c0505 6
hlipka 0:3fa97f2c0505 7 #ifndef __spxmlhandle_hpp__
hlipka 0:3fa97f2c0505 8 #define __spxmlhandle_hpp__
hlipka 0:3fa97f2c0505 9
hlipka 0:3fa97f2c0505 10 class SP_XmlNode;
hlipka 0:3fa97f2c0505 11
hlipka 0:3fa97f2c0505 12 class SP_XmlElementNode;
hlipka 0:3fa97f2c0505 13 class SP_XmlCDataNode;
hlipka 0:3fa97f2c0505 14 class SP_XmlCommentNode;
hlipka 0:3fa97f2c0505 15
hlipka 0:3fa97f2c0505 16 /**
hlipka 0:3fa97f2c0505 17 * This class is a clone of TinyXML's TiXmlHandle class.
hlipka 0:3fa97f2c0505 18 *
hlipka 0:3fa97f2c0505 19 *
hlipka 0:3fa97f2c0505 20 * A SP_XmlHandle is a class that wraps a node pointer with null checks; this is
hlipka 0:3fa97f2c0505 21 * an incredibly useful thing. Note that SP_XmlHandle is not part of the SPXml
hlipka 0:3fa97f2c0505 22 * DOM structure. It is a separate utility class.
hlipka 0:3fa97f2c0505 23 *
hlipka 0:3fa97f2c0505 24
hlipka 0:3fa97f2c0505 25 Take an example:
hlipka 0:3fa97f2c0505 26 @verbatim
hlipka 0:3fa97f2c0505 27 <Document>
hlipka 0:3fa97f2c0505 28 <Element attributeA = "valueA">
hlipka 0:3fa97f2c0505 29 <Child attributeB = "value1" />
hlipka 0:3fa97f2c0505 30 <Child attributeB = "value2" />
hlipka 0:3fa97f2c0505 31 </Element>
hlipka 0:3fa97f2c0505 32 <Document>
hlipka 0:3fa97f2c0505 33 @endverbatim
hlipka 0:3fa97f2c0505 34
hlipka 0:3fa97f2c0505 35 Assuming you want the value of "attributeB" in the 2nd "Child" element, a
hlipka 0:3fa97f2c0505 36 SP_XmlHandle checks for null pointers so it is perfectly safe and correct to use:
hlipka 0:3fa97f2c0505 37
hlipka 0:3fa97f2c0505 38 @verbatim
hlipka 0:3fa97f2c0505 39 SP_XmlHandle rootHandle( parser.getDocument()->getRootElement() );
hlipka 0:3fa97f2c0505 40 SP_XmlElementNode * child2 = rootHandle.getChild( "Element" )
hlipka 0:3fa97f2c0505 41 .getChild( "Child", 1 ).toElement();
hlipka 0:3fa97f2c0505 42
hlipka 0:3fa97f2c0505 43 if( child2 ) {
hlipka 0:3fa97f2c0505 44 // do something
hlipka 0:3fa97f2c0505 45 }
hlipka 0:3fa97f2c0505 46 @endverbatim
hlipka 0:3fa97f2c0505 47 *
hlipka 0:3fa97f2c0505 48 */
hlipka 0:3fa97f2c0505 49
hlipka 0:3fa97f2c0505 50 class SP_XmlHandle {
hlipka 0:3fa97f2c0505 51 public:
hlipka 0:3fa97f2c0505 52 SP_XmlHandle( SP_XmlNode * node );
hlipka 0:3fa97f2c0505 53 SP_XmlHandle( const SP_XmlHandle & ref );
hlipka 0:3fa97f2c0505 54 SP_XmlHandle & operator=( const SP_XmlHandle & ref );
hlipka 0:3fa97f2c0505 55
hlipka 0:3fa97f2c0505 56 ~SP_XmlHandle();
hlipka 0:3fa97f2c0505 57
hlipka 0:3fa97f2c0505 58 SP_XmlHandle getChild( const char * name, int index = 0 ) const;
hlipka 0:3fa97f2c0505 59
hlipka 0:3fa97f2c0505 60 SP_XmlHandle getChild( int index ) const;
hlipka 0:3fa97f2c0505 61
hlipka 0:3fa97f2c0505 62 SP_XmlHandle getElement( int index ) const;
hlipka 0:3fa97f2c0505 63
hlipka 0:3fa97f2c0505 64 SP_XmlNode * toNode();
hlipka 0:3fa97f2c0505 65
hlipka 0:3fa97f2c0505 66 SP_XmlElementNode * toElement();
hlipka 0:3fa97f2c0505 67
hlipka 0:3fa97f2c0505 68 SP_XmlCDataNode * toCData();
hlipka 0:3fa97f2c0505 69
hlipka 0:3fa97f2c0505 70 private:
hlipka 0:3fa97f2c0505 71 SP_XmlNode * mNode;
hlipka 0:3fa97f2c0505 72 };
hlipka 0:3fa97f2c0505 73
hlipka 0:3fa97f2c0505 74 #endif
hlipka 0:3fa97f2c0505 75