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 2007 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 __spdomparser_hpp__
hlipka 0:3fa97f2c0505 8 #define __spdomparser_hpp__
hlipka 0:3fa97f2c0505 9
hlipka 0:3fa97f2c0505 10 class SP_XmlNode;
hlipka 0:3fa97f2c0505 11 class SP_XmlDocument;
hlipka 0:3fa97f2c0505 12 class SP_XmlElementNode;
hlipka 0:3fa97f2c0505 13 class SP_XmlDocDeclNode;
hlipka 0:3fa97f2c0505 14 class SP_XmlDocTypeNode;
hlipka 0:3fa97f2c0505 15 class SP_XmlPullParser;
hlipka 0:3fa97f2c0505 16 class SP_XmlStringBuffer;
hlipka 0:3fa97f2c0505 17
hlipka 0:3fa97f2c0505 18 /// parse string to xml node tree
hlipka 0:3fa97f2c0505 19 class SP_XmlDomParser {
hlipka 0:3fa97f2c0505 20 public:
hlipka 0:3fa97f2c0505 21 SP_XmlDomParser();
hlipka 0:3fa97f2c0505 22 ~SP_XmlDomParser();
hlipka 0:3fa97f2c0505 23
hlipka 0:3fa97f2c0505 24 /// append more input xml source
hlipka 0:3fa97f2c0505 25 /// @return how much byte has been consumed
hlipka 0:3fa97f2c0505 26 int append( const char * source, int len );
hlipka 0:3fa97f2c0505 27
hlipka 0:3fa97f2c0505 28 /// @return NOT NULL : the detail error message
hlipka 0:3fa97f2c0505 29 /// @return NULL : no error
hlipka 0:3fa97f2c0505 30 const char * getError();
hlipka 0:3fa97f2c0505 31
hlipka 0:3fa97f2c0505 32 /// get the parse result
hlipka 0:3fa97f2c0505 33 const SP_XmlDocument * getDocument() const;
hlipka 0:3fa97f2c0505 34
hlipka 0:3fa97f2c0505 35 void setIgnoreWhitespace( int ignoreWhitespace );
hlipka 0:3fa97f2c0505 36
hlipka 0:3fa97f2c0505 37 int getIgnoreWhitespace();
hlipka 0:3fa97f2c0505 38
hlipka 0:3fa97f2c0505 39 const char * getEncoding();
hlipka 0:3fa97f2c0505 40
hlipka 0:3fa97f2c0505 41 private:
hlipka 0:3fa97f2c0505 42 void buildTree();
hlipka 0:3fa97f2c0505 43
hlipka 0:3fa97f2c0505 44 SP_XmlDomParser( SP_XmlDomParser & );
hlipka 0:3fa97f2c0505 45 SP_XmlDomParser & operator=( SP_XmlDomParser & );
hlipka 0:3fa97f2c0505 46
hlipka 0:3fa97f2c0505 47 SP_XmlPullParser * mParser;
hlipka 0:3fa97f2c0505 48 SP_XmlDocument * mDocument;
hlipka 0:3fa97f2c0505 49 SP_XmlElementNode * mCurrent;
hlipka 0:3fa97f2c0505 50 };
hlipka 0:3fa97f2c0505 51
hlipka 0:3fa97f2c0505 52 /// serialize xml node tree to string
hlipka 0:3fa97f2c0505 53 class SP_XmlDomBuffer {
hlipka 0:3fa97f2c0505 54 public:
hlipka 0:3fa97f2c0505 55 SP_XmlDomBuffer( const SP_XmlNode * node, int indent = 1 );
hlipka 0:3fa97f2c0505 56 SP_XmlDomBuffer( const char * encoding, const SP_XmlNode * node, int indent = 1 );
hlipka 0:3fa97f2c0505 57 ~SP_XmlDomBuffer();
hlipka 0:3fa97f2c0505 58
hlipka 0:3fa97f2c0505 59 const char * getBuffer() const;
hlipka 0:3fa97f2c0505 60 int getSize() const;
hlipka 0:3fa97f2c0505 61
hlipka 0:3fa97f2c0505 62 private:
hlipka 0:3fa97f2c0505 63 SP_XmlDomBuffer( SP_XmlDomBuffer & );
hlipka 0:3fa97f2c0505 64 SP_XmlDomBuffer & operator=( SP_XmlDomBuffer & );
hlipka 0:3fa97f2c0505 65
hlipka 0:3fa97f2c0505 66 static void dumpDocDecl( const char * encoding,
hlipka 0:3fa97f2c0505 67 const SP_XmlDocDeclNode * docDecl,
hlipka 0:3fa97f2c0505 68 SP_XmlStringBuffer * buffer, int level );
hlipka 0:3fa97f2c0505 69 static void dumpDocType( const char * encoding,
hlipka 0:3fa97f2c0505 70 const SP_XmlDocTypeNode * docType,
hlipka 0:3fa97f2c0505 71 SP_XmlStringBuffer * buffer, int level );
hlipka 0:3fa97f2c0505 72 static void dump( const char * encoding,
hlipka 0:3fa97f2c0505 73 const SP_XmlNode * node,
hlipka 0:3fa97f2c0505 74 SP_XmlStringBuffer * buffer, int level );
hlipka 0:3fa97f2c0505 75 static void dumpElement( const char * encoding,
hlipka 0:3fa97f2c0505 76 const SP_XmlNode * node,
hlipka 0:3fa97f2c0505 77 SP_XmlStringBuffer * buffer, int level );
hlipka 0:3fa97f2c0505 78
hlipka 0:3fa97f2c0505 79 SP_XmlStringBuffer * mBuffer;
hlipka 0:3fa97f2c0505 80 };
hlipka 0:3fa97f2c0505 81
hlipka 0:3fa97f2c0505 82 #endif
hlipka 0:3fa97f2c0505 83