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!!
main.cpp@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 | #include "mbed.h" |
rolf | 0:37e8c5cd04e8 | 2 | #include "fastxml.h" |
rolf | 0:37e8c5cd04e8 | 3 | |
rolf | 0:37e8c5cd04e8 | 4 | DigitalOut myled(LED1); |
rolf | 0:37e8c5cd04e8 | 5 | |
rolf | 0:37e8c5cd04e8 | 6 | class tmpr : public FastXmlInterface { |
rolf | 0:37e8c5cd04e8 | 7 | public: |
rolf | 0:37e8c5cd04e8 | 8 | virtual bool processElement(const char *name, int argc, const char **argv, const char *data, int lineno) { |
rolf | 0:37e8c5cd04e8 | 9 | printf("::%s\n", name); |
rolf | 0:37e8c5cd04e8 | 10 | if(strncmp(name, "tmpr", 4)==0) { |
rolf | 0:37e8c5cd04e8 | 11 | printf("tmpr: %s\n", data); |
rolf | 0:37e8c5cd04e8 | 12 | } |
rolf | 0:37e8c5cd04e8 | 13 | return true; |
rolf | 0:37e8c5cd04e8 | 14 | } |
rolf | 0:37e8c5cd04e8 | 15 | }; |
rolf | 0:37e8c5cd04e8 | 16 | |
rolf | 0:37e8c5cd04e8 | 17 | const char *code = { |
rolf | 0:37e8c5cd04e8 | 18 | "<root>\r\n" |
rolf | 0:37e8c5cd04e8 | 19 | " <chan1>\r\n" |
rolf | 0:37e8c5cd04e8 | 20 | " <tmpr>23.7</tmpr>\r\n" |
rolf | 0:37e8c5cd04e8 | 21 | " </chan1>\r\n" |
rolf | 0:37e8c5cd04e8 | 22 | " <chan2>\r\n" |
rolf | 0:37e8c5cd04e8 | 23 | " <tmpr>23.7</tmpr>\r\n" |
rolf | 0:37e8c5cd04e8 | 24 | " </chan2>\r\n" |
rolf | 0:37e8c5cd04e8 | 25 | "</root>\r\n" |
rolf | 0:37e8c5cd04e8 | 26 | }; |
rolf | 0:37e8c5cd04e8 | 27 | |
rolf | 0:37e8c5cd04e8 | 28 | int main() { |
rolf | 0:37e8c5cd04e8 | 29 | FastXml *xml = createFastXml(); |
rolf | 0:37e8c5cd04e8 | 30 | FastXmlInterface *tmp = new tmpr(); |
rolf | 0:37e8c5cd04e8 | 31 | xml->processXml(code, strlen(code), tmp); |
rolf | 0:37e8c5cd04e8 | 32 | while(1) { |
rolf | 0:37e8c5cd04e8 | 33 | myled = 1; |
rolf | 0:37e8c5cd04e8 | 34 | wait(0.2); |
rolf | 0:37e8c5cd04e8 | 35 | myled = 0; |
rolf | 0:37e8c5cd04e8 | 36 | wait(0.2); |
rolf | 0:37e8c5cd04e8 | 37 | } |
rolf | 0:37e8c5cd04e8 | 38 | } |