]> git.mxchange.org Git - flightgear.git/blob - utils/xmlgrep/README
4a35d1d0c5d2f1af8cf85d0c6ed1b67550f2e54e
[flightgear.git] / utils / xmlgrep / README
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.
7
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 or when a request is made to
11 copy a node.
12
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.
15 {
16    void *xid;
17
18    xid = xmlOpen("/tmp/file.xml");
19    xpos = xmlGetNodeDouble(xid, "/configuration/x-pos");
20    ypos = xmlGetNodeDouble(xid, "/configuration/y-pos");
21    zpos = xmlGetNodeDouble(xid, "/configuration/z-pos");
22    xmlClose(xid);
23 }
24
25 While it is certainly possible to access every node directly by calling the
26 xmlGetNode(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. This is because the XML-id holds the boundaries of the
29 (parent)node which limits the searching area resulting in improved searching
30 speed.
31 {
32    void *xnid;
33    char *s;
34
35    xnid = xmlGetNode(id, "/configuration/setup/");
36    version = xmlGetNodeDouble(xnid, "version");
37    s = xmlGetNodeString(xnid, "author");
38    if (s) author = s;
39    free(s);
40    free(xnid);
41 }
42
43 Overview of the available functions:
44  ----------------------------------------------------------------------------- 
45 #
46 # Functions to Open and Close the XML file
47 # e.g.
48 #   id = xmlOpen("/tmp/file.xml");
49 #   xmlClose(id);
50 #
51 void *xmlOpen(const char *);
52 void xmlClose(const void *);
53
54 #
55 # Get the Id of a node at the specified path
56 # e.g.
57 #    xnid = xmlGetNode(id, "/path/to/specified/node");
58 #
59 void *xmlGetNode(const void *, const char *);
60 void *xmlCopyNode(void *, const char *);
61
62 #
63 # Functions to walk the node tree and process them one by one.
64 # e.g.
65 #   xmid = xmlMarkId(id);
66 #   num = xmlGetNumElements(xmid);
67 #   for (i=0; i<num; i++) {
68 #      if (xmlGetNextElement(id, xmid, "element") != 0) {
69 #         if ((s = xmlGetString(xmid)) != 0) {
70 #            printf("%s\n", s);
71 #            free(s);
72 #         }
73 #      }
74 #   }
75 #   free(xmid);
76 #
77 void *xmlMarkId(void *);
78 unsigned int xmlGetNumElements(void *, const char *);
79 void *xmlGetNextElement(const void *, void *, const char *);
80
81 #
82 # These functions work on the current node.
83 # e.g.
84 #    xnid = xmlGetNode(id, "/path/to/last/node");
85 #    i = xmlGetInt(xnid);
86 # or
87 #    xnid = xmlGetNode(id, "/path/to/specified/node");
88 #    if (xmlCompareString(xnid, "value") == 0) printf("We have a match!\n");
89 #
90 long int xmlGetInt(void *);
91 double xmlGetDouble(void *);
92 char *xmlGetString(void *);
93 int xmlCompareString(const void *, const char *);
94
95 #
96 # These functions work on a specified node path
97 # e.g.
98 #    d = xmlGetNodeDouble(id, "/path/to/node");
99 # or
100 #    xnid = xmlGetNode(id, "/path/to");
101 #    i = xmlGetNodeInt(xnid, "node");
102 #
103 long int xmlGetNodeInt(void *, const char *);
104 double xmlGetNodeDouble(void *, const char *);
105 char *xmlGetNodeString(void *, const char *);
106 unsigned xmlCopyNodeString(void *, const char *, char *, const unsigned int);
107 int xmlCompareNodeString(const void *, const char *, const char *);