X-Git-Url: http://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Fttxml%2Fttxml.h;h=33cb64fe977add4d6b67ef60f4deedc00d618f18;hp=0b8c156d84d9907fdf4a2af3950f82d264552682;hb=56023cca5f66a40646a1e807c3d10af6e5913623;hpb=a89ccb89e84236ba0226038a1cbecc901e95614b diff --git a/ccan/ttxml/ttxml.h b/ccan/ttxml/ttxml.h index 0b8c156d..33cb64fe 100644 --- a/ccan/ttxml/ttxml.h +++ b/ccan/ttxml/ttxml.h @@ -1,4 +1,36 @@ +#ifndef CCAN_TTXML_H +#define CCAN_TTXML_H +/** + * ttxml - tiny XML library for parsing (trusted!) XML documents. + * + * This parses an XML file into a convenient data structure. + * + * Example: + * #include + * #include + * + * int main(int argc, char *argv[]) + * { + * XmlNode *xml, *tmp; + * + * xml = xml_load("./test/test.xml2"); + * if(!xml)return 1; + * + * tmp = xml_find(xml, "childnode"); + * + * printf("%s: %s\n", xml->name, xml_attr(tmp, "attribute")); + * + * xml_free(xml); + * + * return 0; + * } + * + * License: GPL + * Author: Daniel Burke + */ + +/* Every node is one of these */ typedef struct XmlNode { char * name; char ** attrib; @@ -7,10 +39,19 @@ typedef struct XmlNode { struct XmlNode * next; } XmlNode; +/* It's all pretty straight forward except for the attrib. + * + * Attrib is an array of char*, that is 2x the size of nattrib. + * Each pair of char* points to the attribute name & the attribute value, + * if present. + * + * If it's a text node, then name = "text", and attrib[1] = the body of text. + * This is the only case where there will be an attribute with a null name. + */ -XmlNode* xml_new(char * name, char * attrib); XmlNode* xml_load(const char * filename); void xml_free(XmlNode *target); char* xml_attr(XmlNode *x, const char *name); XmlNode * xml_find(XmlNode *xml, const char *name); +#endif /* CCAN_TTXML_H */