XML parsing aide
XMLaide.cpp@1:ad5fd8c29c1f, 2015-06-27 (annotated)
- Committer:
- takashikojo
- Date:
- Sat Jun 27 10:35:34 2015 +0000
- Revision:
- 1:ad5fd8c29c1f
- Parent:
- 0:369a19fba8a4
- Child:
- 2:c86701a4f5b0
XML parsing aide
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
takashikojo | 0:369a19fba8a4 | 1 | #include <mbed.h> |
takashikojo | 0:369a19fba8a4 | 2 | #include "XMLaide.h" |
takashikojo | 1:ad5fd8c29c1f | 3 | #include <algorithm> |
takashikojo | 0:369a19fba8a4 | 4 | |
takashikojo | 0:369a19fba8a4 | 5 | const char *XML_getTag(const char *p, const char *name) |
takashikojo | 0:369a19fba8a4 | 6 | { |
takashikojo | 0:369a19fba8a4 | 7 | const char *find ; |
takashikojo | 0:369a19fba8a4 | 8 | #define TAG_SIZE 20 |
takashikojo | 0:369a19fba8a4 | 9 | char tag[TAG_SIZE] = "<" ; |
takashikojo | 0:369a19fba8a4 | 10 | |
takashikojo | 0:369a19fba8a4 | 11 | find = strstr(p, strcat(tag, name)) ; |
takashikojo | 0:369a19fba8a4 | 12 | if(find) { |
takashikojo | 0:369a19fba8a4 | 13 | find = strchr(find, '>') ; |
takashikojo | 0:369a19fba8a4 | 14 | return find + 1 ; |
takashikojo | 0:369a19fba8a4 | 15 | } else return NULL ; |
takashikojo | 0:369a19fba8a4 | 16 | } |
takashikojo | 0:369a19fba8a4 | 17 | |
takashikojo | 1:ad5fd8c29c1f | 18 | const char *XML_getElement(const char *p, char *element, int size) |
takashikojo | 0:369a19fba8a4 | 19 | { |
takashikojo | 0:369a19fba8a4 | 20 | const char *find ; |
takashikojo | 0:369a19fba8a4 | 21 | find = strstr(p, "</") ; |
takashikojo | 0:369a19fba8a4 | 22 | |
takashikojo | 0:369a19fba8a4 | 23 | if(find) { |
takashikojo | 1:ad5fd8c29c1f | 24 | strncpy(element, p, min((find-p), size)) ; |
takashikojo | 1:ad5fd8c29c1f | 25 | element[min((find-p), size)] = '\0' ; |
takashikojo | 0:369a19fba8a4 | 26 | } else *element = '\0' ; |
takashikojo | 0:369a19fba8a4 | 27 | |
takashikojo | 0:369a19fba8a4 | 28 | return find ; |
takashikojo | 0:369a19fba8a4 | 29 | } |