In the previous example, the user Data is employed to keep track of the indentation level that should be used when printing elements and attributes to the standard output.Expat has many advantages: it is very fast and very portable.
One strategy would be simply to create global functions to register with expat.
Those functions can receive a pointer to the data you want to modify while reading the file (e.g., a Count object that will store the number of characters in the file), and then all you have to do is register them with expat.
Here is a sample of a typical expat use in C: /* This is a simple demonstration of how to use expat.
This program reads an XML document from standard input and writes a line with the name of each element to standard output, indenting child elements by one tab stop more than their parent element.
Several toolkits and libraries have been produced for C based manipulation.
Those toolkits mainly fall into two categories: event-driven processors and object model construction processors. In an event-driven approach for processing XML data, a parser reads the data and notifies specialized handlers that undertake the desired actions.
We will examine two things: the main APIs and strategies for parsing and manipulating XML in your C application, and the practical uses and tradeoffs of approaches to XML parsing.
To get the most from this article, a basic understanding of the C language is required.
A standard interface for SAX in C has not yet been developed.
Nevertheless, the importance and growing use of SAX in C XML based applications is unquestionable, and makes it an important topic in our discussion.
It is also under the GPL (the GNU General Public License), which means you can freely use and distribute it.