
This demo contains a port of the FastXML library. FastXML was hosted on geocities and is offline now. The library itself is contained into two files header and cpp and very easy to use. I don't know how many RAM it eats up but XML is probably not the best thing to use on an microcontroler. Decide your self but be warned. I told you so!!
fastxml/fastxml.h@0:37e8c5cd04e8, 2009-12-11 (annotated)
- Committer:
- rolf
- Date:
- Fri Dec 11 15:32:41 2009 +0000
- Revision:
- 0:37e8c5cd04e8
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
rolf | 0:37e8c5cd04e8 | 1 | #ifndef FAST_XML_H |
rolf | 0:37e8c5cd04e8 | 2 | #define FAST_XML_H |
rolf | 0:37e8c5cd04e8 | 3 | |
rolf | 0:37e8c5cd04e8 | 4 | /*! |
rolf | 0:37e8c5cd04e8 | 5 | ** |
rolf | 0:37e8c5cd04e8 | 6 | ** Copyright (c) 2009 by John W. Ratcliff mailto:jratcliff@infiniplex.net |
rolf | 0:37e8c5cd04e8 | 7 | ** |
rolf | 0:37e8c5cd04e8 | 8 | ** The MIT license: |
rolf | 0:37e8c5cd04e8 | 9 | ** |
rolf | 0:37e8c5cd04e8 | 10 | ** Permission is hereby granted, MEMALLOC_FREE of charge, to any person obtaining a copy |
rolf | 0:37e8c5cd04e8 | 11 | ** of this software and associated documentation files (the "Software"), to deal |
rolf | 0:37e8c5cd04e8 | 12 | ** in the Software without restriction, including without limitation the rights |
rolf | 0:37e8c5cd04e8 | 13 | ** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
rolf | 0:37e8c5cd04e8 | 14 | ** copies of the Software, and to permit persons to whom the Software is furnished |
rolf | 0:37e8c5cd04e8 | 15 | ** to do so, subject to the following conditions: |
rolf | 0:37e8c5cd04e8 | 16 | ** |
rolf | 0:37e8c5cd04e8 | 17 | ** The above copyright notice and this permission notice shall be included in all |
rolf | 0:37e8c5cd04e8 | 18 | ** copies or substantial portions of the Software. |
rolf | 0:37e8c5cd04e8 | 19 | |
rolf | 0:37e8c5cd04e8 | 20 | ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
rolf | 0:37e8c5cd04e8 | 21 | ** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
rolf | 0:37e8c5cd04e8 | 22 | ** FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
rolf | 0:37e8c5cd04e8 | 23 | ** AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
rolf | 0:37e8c5cd04e8 | 24 | ** WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
rolf | 0:37e8c5cd04e8 | 25 | ** CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
rolf | 0:37e8c5cd04e8 | 26 | |
rolf | 0:37e8c5cd04e8 | 27 | */ |
rolf | 0:37e8c5cd04e8 | 28 | |
rolf | 0:37e8c5cd04e8 | 29 | |
rolf | 0:37e8c5cd04e8 | 30 | // This code snippet provides an extremely lightweight and fast XML parser. |
rolf | 0:37e8c5cd04e8 | 31 | // This parser only handles data elements as if they were streamed data. |
rolf | 0:37e8c5cd04e8 | 32 | // It is important to note that all pointers returned by this parser are |
rolf | 0:37e8c5cd04e8 | 33 | // persistent for the lifetime of the FastXml class. This means you can cache |
rolf | 0:37e8c5cd04e8 | 34 | // copies of the pointers (rather than copying any data) if this matches your |
rolf | 0:37e8c5cd04e8 | 35 | // needs. |
rolf | 0:37e8c5cd04e8 | 36 | |
rolf | 0:37e8c5cd04e8 | 37 | |
rolf | 0:37e8c5cd04e8 | 38 | // Simpy call createFastXml to get a copy of the FastXml parsing interface |
rolf | 0:37e8c5cd04e8 | 39 | // To parse an XML file, have your application inherit the pure virtual |
rolf | 0:37e8c5cd04e8 | 40 | // interface called 'FastXmlInterface' and implement the single method 'processElement' |
rolf | 0:37e8c5cd04e8 | 41 | // |
rolf | 0:37e8c5cd04e8 | 42 | // For each element in the XML file you will get a callback with the following |
rolf | 0:37e8c5cd04e8 | 43 | // data. |
rolf | 0:37e8c5cd04e8 | 44 | // |
rolf | 0:37e8c5cd04e8 | 45 | // 'elementName' the name of the element (this pointer is persistent) |
rolf | 0:37e8c5cd04e8 | 46 | // 'argc' The total number of attributes and values for this element. |
rolf | 0:37e8c5cd04e8 | 47 | // The number of attribute/value pairs is equal to argc/2 |
rolf | 0:37e8c5cd04e8 | 48 | // 'argv' The attribute/value pairs in the form of attribute/value, attribute/value.. |
rolf | 0:37e8c5cd04e8 | 49 | // These pointers are persistent and can be cached if needed (until FastXml is released) |
rolf | 0:37e8c5cd04e8 | 50 | // 'elementData' optional data (i.e. text) associated with the element. If this is a null pointer |
rolf | 0:37e8c5cd04e8 | 51 | // then the element had no data. This pointer is persistent. |
rolf | 0:37e8c5cd04e8 | 52 | // 'lineno' The line number in the source XML file. |
rolf | 0:37e8c5cd04e8 | 53 | // |
rolf | 0:37e8c5cd04e8 | 54 | // After calling your routine 'processElement' you must return 'true' to continue parsing |
rolf | 0:37e8c5cd04e8 | 55 | // If you want to stop parsing early, return false. |
rolf | 0:37e8c5cd04e8 | 56 | // |
rolf | 0:37e8c5cd04e8 | 57 | // If the call to process an XML file fails, it will return false. |
rolf | 0:37e8c5cd04e8 | 58 | // You can then call the method 'getError' to get a description of why it failed |
rolf | 0:37e8c5cd04e8 | 59 | // and on what line number of the source XML file it occurred. |
rolf | 0:37e8c5cd04e8 | 60 | |
rolf | 0:37e8c5cd04e8 | 61 | class FastXmlInterface { |
rolf | 0:37e8c5cd04e8 | 62 | public: |
rolf | 0:37e8c5cd04e8 | 63 | // return true to continue processing the XML document, false to skip. |
rolf | 0:37e8c5cd04e8 | 64 | virtual bool processElement(const char *elementName, // name of the element |
rolf | 0:37e8c5cd04e8 | 65 | int argc, // number of attributes |
rolf | 0:37e8c5cd04e8 | 66 | const char **argv, // list of attributes. |
rolf | 0:37e8c5cd04e8 | 67 | const char *elementData, // element data, null if none |
rolf | 0:37e8c5cd04e8 | 68 | int lineno) = 0; // line number in the source XML file |
rolf | 0:37e8c5cd04e8 | 69 | |
rolf | 0:37e8c5cd04e8 | 70 | }; |
rolf | 0:37e8c5cd04e8 | 71 | |
rolf | 0:37e8c5cd04e8 | 72 | class FastXml { |
rolf | 0:37e8c5cd04e8 | 73 | public: |
rolf | 0:37e8c5cd04e8 | 74 | virtual bool processXml(const char *inputData,unsigned int dataLen,FastXmlInterface *iface) = 0; |
rolf | 0:37e8c5cd04e8 | 75 | virtual const char * getError(int &lineno) = 0; // report the reason for a parsing error, and the line number where it occurred. |
rolf | 0:37e8c5cd04e8 | 76 | }; |
rolf | 0:37e8c5cd04e8 | 77 | |
rolf | 0:37e8c5cd04e8 | 78 | FastXml *createFastXml(void); |
rolf | 0:37e8c5cd04e8 | 79 | void releaseFastXml(FastXml *f); |
rolf | 0:37e8c5cd04e8 | 80 | |
rolf | 0:37e8c5cd04e8 | 81 | #endif |