1 This library is specially designed for reading xml configuration files and
2 to be as low on memory management as possible. Modifying or writing xml files
3 is not planned for the future. In most situations being able to gather data
4 by reading an xml file is more than enough and the read-only decision
5 provides a number of advantages over a one-size fits all approach. For isntance
6 the memory footprint can be kept low and the library can be kept simple.
8 To achieve these goals the mmap function is used to map the configuration file
9 to a memory region. The only places where memory is allocated is when creating
10 a new XML-id, when requesting a string from a node, when requestiong the node
11 name or when a request is made to copy a node into a new memory region.
13 Using this library should be pretty simple for most tasks; just open a file,
14 read every parameter one by one and close the id again.
18 xid = xmlOpen("/tmp/file.xml");
19 xpos = xmlNodeGetDouble(xid, "/configuration/x-pos");
20 ypos = xmlNodeGetDouble(xid, "/configuration/y-pos");
21 zpos = xmlNodeGetDouble(xid, "/configuration/z-pos");
25 While it is certainly possible to access every node directly by calling the
26 xmlNodeGet(Int/Double/String) functions, when more than one node need to be
27 gathered from a parent node it is advised to get the id of the parent node
28 and work from there since the XML-id holds the boundaries of the (parent)node
29 which limits the searching area resulting in improved searching speed.
34 xnid = xmlNodeGet(id, "/configuration/setup/");
35 version = xmlNodeGetDouble(xnid, "version");
36 s = xmlNodeGetString(xnid, "author");
42 Overview of the available functions:
43 -----------------------------------------------------------------------------
45 # Functions to Open and Close the XML file
47 # id = xmlOpen("/tmp/file.xml");
50 void *xmlOpen(const char *);
51 void xmlClose(const void *);
54 # Get the Id of a node at the specified path
56 # xnid = xmlNodeGet(id, "/path/to/specified/node");
58 void *xmlNodeGet(const void *, const char *);
59 void *xmlNodeCopy(void *, const char *);
62 # Functions to walk the node tree and process them one by one.
64 # xmid = xmlMarkId(id);
65 # num = xmlNodeGetNum(xmid);
66 # for (i=0; i<num; i++) {
67 # if (xmlNodeGetPos(id, xmid, "element", i) != 0) {
68 # if ((s = xmlGetString(xmid)) != 0) {
76 void *xmlMarkId(void *);
77 unsigned int xmlNodeGetNum(void *, const char *);
78 void *xmlNodeGetPos(const void *, void *, const char *, int);
81 # Get the name of the current node
83 char *xmlNodeGetName(void *);
84 size_t xmlNodeCopyName(void *, const char *, size_t);
87 # These functions work on the current node.
89 # xnid = xmlNodeGet(id, "/path/to/last/node");
90 # i = xmlGetInt(xnid);
92 # xnid = xmlNodeGet(id, "/path/to/specified/node");
93 # if (xmlCompareString(xnid, "value") == 0) printf("We have a match!\n");
95 long int xmlGetInt(void *);
96 double xmlGetDouble(void *);
97 char *xmlGetString(void *);
98 size_t xmlCopyString(void *, char *, const size_t);
99 int xmlCompareString(const void *, const char *);
102 # These functions work on a specified node path
104 # d = xmlNodeGetDouble(id, "/path/to/node");
106 # xnid = xmlNodeGet(id, "/path/to");
107 # i = xmlNodeGetInt(xnid, "node");
109 long int xmlNodeGetInt(void *, const char *);
110 double xmlNodeGetDouble(void *, const char *);
111 char *xmlNodeGetString(void *, const char *);
112 size_t xmlNodeCopyString(void *, const char *, char *, const size_t);
113 int xmlNodeCompareString(const void *, const char *, const char *);
116 # These functions work on a specified atribute
118 # i = xmlAttributeGetInt(id, "n");
121 # s = xmlNodeGetString(id, "type");
122 # if (s) printf("node is of type '%s'\n", s);
125 long int xmlAttributeGetInt(const void *, const char *);
126 double xmlAttributeGetDouble(const void *, const char *);
127 char *xmlAttributeGetString(const void *, const char *);
128 size_t xmlAttributeCopyString(const void *, const char *, const char *, size_t);
129 int xmlAttributeCompareString(const void *, const char *, const char *);
132 # Error detection and reporting functions
134 # char *err_str = xmlErrorGetString(id, 0);
135 # size_t err_lineno = xmlErrorGetLineNo(id, 0);
136 # int err = xmlErrorGetNo(id, 1); /* clear last error */
137 # if (err) printf("Error #%i at line %u: '%s'\n", err, err_lineno, err_str);
139 int xmlErrorGetNo(const void *, int);
140 size_t xmlErrorGetLineNo(const void *, int);
141 const char *xmlErrorGetString(const void *, int);