]> git.ozlabs.org Git - ccan/blob - ccan/ttxml/ttxml.h
check_type: fix incorrect documentation.
[ccan] / ccan / ttxml / ttxml.h
1 #ifndef CCAN_TTXML_H
2 #define CCAN_TTXML_H
3
4 /**
5  * ttxml - tiny XML library for parsing (trusted!) XML documents.
6  *
7  * This parses an XML file into a convenient data structure.
8  *
9  * Example:
10  * #include <ccan/ttxml/ttxml.h>
11  * #include <stdio.h>
12  *
13  * int main(int argc, char *argv[])
14  * {
15  *      XmlNode *xml, *tmp;
16  *
17  *      xml = xml_load("./test/test.xml2");
18  *      if(!xml)return 1;
19  *
20  *      tmp = xml_find(xml, "childnode");
21  *
22  *      printf("%s: %s\n", xml->name, xml_attr(tmp, "attribute"));
23  *
24  *      xml_free(xml);
25  *
26  *      return 0;
27  * }
28  *
29  * License: GPL
30  * Author: Daniel Burke <dan.p.burke@gmail.com>
31  */
32
33 /* Every node is one of these */
34 typedef struct XmlNode {
35         char * name;
36         char ** attrib;
37         int nattrib;
38         struct XmlNode * child;
39         struct XmlNode * next;
40 } XmlNode;
41
42 /* It's all pretty straight forward except for the attrib.
43  *
44  * Attrib is an array of char*, that is 2x the size of nattrib.
45  * Each pair of char* points to the attribute name & the attribute value,
46  * if present.
47  *
48  * If it's a text node, then name = "text", and attrib[1] = the body of text.
49  * This is the only case where there will be an attribute with a null name.
50  */
51
52 XmlNode* xml_load(const char * filename);
53 void xml_free(XmlNode *target);
54 char* xml_attr(XmlNode *x, const char *name);
55 XmlNode * xml_find(XmlNode *xml, const char *name);
56
57 #endif /* CCAN_TTXML_H */