summaryrefslogtreecommitdiff
path: root/ecos/packages/services/ezxml/current/doc/ezxml.txt
blob: 2968e131db162856cb310bdb3b4b334c4b1787af (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
ezXML - XML Parsing C Library
version 0.8

ezXML is a C library for parsing XML documents inspired by simpleXML for PHP.
As the name implies, it's easy to use. It's ideal for parsing xml configuration
files or REST web service responses. It's also fast and lightweight (11k
compiled).  The latest version is available here:
http://prdownloads.sf.net/ezxml/ezxml-0.8.tar.gz?download

Example Usage

Given the following example xml document:

<?xml version="1.0"?>
<formula1>
  <team name="McLaren">
    <driver>
      <name>Kimi Raikkonen</name>
      <points>45</points>
    </driver>
    <driver>
      <name>David Coultard</name>
      <points>24</points>
    </driver>
  </team>
</formula1>

This code snipped prints out a list of drivers, which team they drive for,
and how many championship points they have:

ezxml_t f1 = ezxml_parse_file("formula1.xml"), team, driver;
const char *teamname;

for (team = ezxml_child(f1, "team"); team; team = team->next) {
    teamname = ezxml_attr(team, "name");
    for (driver = ezxml_child(team, "driver"); driver; driver = driver->next) {
        printf("%s, %s: %s\n", ezxml_child(driver, "name")->txt, teamname,
               ezxml_child(driver, "points")->txt);
    }
}
ezxml_free(f1);

Alternately, the following would print out the name of the second driver of the
first team:

ezxml_t f1 = ezxml_parse_file("formula1.xml");

printf("%s\n", ezxml_get(f1, "team", 0, "driver", 1, "name", -1)->txt);
ezxml_free(f1);

The -1 indicates the end of the argument list. That's pretty much all
there is to it. Complete API documentation can be found in ezxml.h.

Known Limitations

- No support for UTF-16, however UTF-8 is handled correctly. UTF-16 support is
  required for XML 1.0 conformity and will be implimented for the 1.0 release.

- Loads the entire xml document into memory at once and does not allow for
  documents to be passed in a chunk at a time. Large xml files can still be
  handled though through ezxml_parse_file() and ezxml_parse_fd(), which use mmap
  to map the file to a virtual address space and rely on the virtual memory
  system to page in data as needed.

- Ignores DTDs. Parsing of the internal DTD subset is required for XML 1.0
  conformity and will be implimented for the 1.0 release. ezXML is not, and is
  not likely to become, a validating parser.

- In making the character content of tags easy to access, there is no way
  provided to keep track of the location of sub tags relative to the character
  data. Example:

  <doc>line one<br/>
  line two</doc>

  The character content of the doc tag is reported as "line one\nline two", and
  <br/> is reported as a sub tag, but the location of <br/> within the
  character data is not. The function ezxml_toxml() will convert an ezXML
  structure back to xml with sub tag locations intact.

Licensing

ezXML was written by Aaron Voisine <aaron@voisine.org> and is distributed under
the terms of the MIT license, described in license.txt.