README 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. ezXML - XML Parsing C Library
  2. version 0.8.5
  3. ezXML is a C library for parsing XML documents inspired by simpleXML for PHP.
  4. As the name implies, it's easy to use. It's ideal for parsing XML configuration
  5. files or REST web service responses. It's also fast and lightweight (less than
  6. 20k compiled). The latest verions is available here:
  7. http://prdownloads.sf.net/ezxml/ezxml-0.8.6.tar.gz?download
  8. Example Usage
  9. Given the following example XML document:
  10. <?xml version="1.0"?>
  11. <formula1>
  12. <team name="McLaren">
  13. <driver>
  14. <name>Kimi Raikkonen</name>
  15. <points>112</points>
  16. </driver>
  17. <driver>
  18. <name>Juan Pablo Montoya</name>
  19. <points>60</points>
  20. </driver>
  21. </team>
  22. </formula1>
  23. This code snippet prints out a list of drivers, which team they drive for,
  24. and how many championship points they have:
  25. ezxml_t f1 = ezxml_parse_file("formula1.xml"), team, driver;
  26. const char *teamname;
  27. for (team = ezxml_child(f1, "team"); team; team = team->next) {
  28. teamname = ezxml_attr(team, "name");
  29. for (driver = ezxml_child(team, "driver"); driver; driver = driver->next) {
  30. printf("%s, %s: %s\n", ezxml_child(driver, "name")->txt, teamname,
  31. ezxml_child(driver, "points")->txt);
  32. }
  33. }
  34. ezxml_free(f1);
  35. Alternately, the following would print out the name of the second driver on the
  36. first team:
  37. ezxml_t f1 = ezxml_parse_file("formula1.xml");
  38. printf("%s\n", ezxml_get(f1, "team", 0, "driver", 1, "name", -1)->txt);
  39. ezxml_free(f1);
  40. The -1 indicates the end of the argument list. That's pretty much all
  41. there is to it. Complete API documentation can be found in ezxml.h.
  42. Known Limitations
  43. - ezXML is not a validating parser
  44. - Loads the entire XML document into memory at once and does not allow for
  45. documents to be passed in a chunk at a time. Large XML files can still be
  46. handled though through ezxml_parse_file() and ezxml_parse_fd(), which use mmap
  47. to map the file to a virtual address space and rely on the virtual memory
  48. system to page in data as needed.
  49. - Does not currently recognize all possible well-formedness errors. It should
  50. correctly handle all well-formed XML documents and will either ignore or halt
  51. XML processing on well-formedness errors. More well-formedness checking will
  52. be added in subsiquent releases.
  53. - In making the character content of tags easy to access, there is no way
  54. provided to keep track of the location of sub tags relative to the character
  55. data. Example:
  56. <doc>line one<br/>
  57. line two</doc>
  58. The character content of the doc tag is reported as "line one\nline two", and
  59. <br/> is reported as a sub tag, but the location of <br/> within the
  60. character data is not. The function ezxml_toxml() will convert an ezXML
  61. structure back to XML with sub tag locations intact.
  62. Licensing
  63. ezXML was written by Aaron Voisine <aaron@voisine.org> and is distributed under
  64. the terms of the MIT license, described in license.txt.