3 * synopsis: Parse an XML file with an xmlReader
4 * purpose: Demonstrate the use of xmlReaderForFile() to parse an XML file
5 * and dump the informations about the nodes found in the process.
6 * (Note that the XMLReader functions require libxml2 version later
8 * usage: reader1 <filename>
9 * test: reader1 test2.xml > reader1.tmp ; diff reader1.tmp reader1.res ; rm reader1.tmp
10 * author: Daniel Veillard
11 * copy: see Copyright for the status of this software.
15 #include <libxml/xmlreader.h>
17 #ifdef LIBXML_READER_ENABLED
21 * @reader: the xmlReader
23 * Dump information about the current node
26 processNode(xmlTextReaderPtr reader
) {
27 const xmlChar
*name
, *value
;
29 name
= xmlTextReaderConstName(reader
);
33 value
= xmlTextReaderConstValue(reader
);
35 printf("%d %d %s %d %d",
36 xmlTextReaderDepth(reader
),
37 xmlTextReaderNodeType(reader
),
39 xmlTextReaderIsEmptyElement(reader
),
40 xmlTextReaderHasValue(reader
));
44 if (xmlStrlen(value
) > 40)
45 printf(" %.40s...\n", value
);
47 printf(" %s\n", value
);
53 * @filename: the file name to parse
55 * Parse and print information about an XML file.
58 streamFile(const char *filename
) {
59 xmlTextReaderPtr reader
;
62 reader
= xmlReaderForFile(filename
, NULL
, 0);
64 ret
= xmlTextReaderRead(reader
);
67 ret
= xmlTextReaderRead(reader
);
69 xmlFreeTextReader(reader
);
71 fprintf(stderr
, "%s : failed to parse\n", filename
);
74 fprintf(stderr
, "Unable to open %s\n", filename
);
78 int main(int argc
, char **argv
) {
83 * this initialize the library and check potential ABI mismatches
84 * between the version it was compiled for and the actual shared
92 * Cleanup function for the XML library.
96 * this is to debug memory for regression tests
104 fprintf(stderr
, "XInclude support not compiled in\n");