2 * testSAX.c : a small tester program for parsing using the SAX API.
4 * See Copyright for the status of this software.
11 #ifdef LIBXML_READER_ENABLED
15 #ifdef HAVE_SYS_TYPES_H
16 #include <sys/types.h>
18 #ifdef HAVE_SYS_STAT_H
35 #include <libxml/xmlreader.h>
42 static int consumed = 0;
44 static void usage(const char *progname) {
45 printf("Usage : %s [options] XMLfiles ...\n", progname);
46 printf("\tParse the XML files using the xmlTextReader API\n");
47 printf("\t --count: count the number of attribute and elements\n");
48 printf("\t --valid: validate the document\n");
49 printf("\t --consumed: count the number of bytes consumed\n");
52 static int elem, attrs;
54 static void processNode(xmlTextReaderPtr reader) {
57 type = xmlTextReaderNodeType(reader);
61 attrs += xmlTextReaderAttributeCount(reader);
66 static void handleFile(const char *filename) {
67 xmlTextReaderPtr reader;
75 reader = xmlNewTextReaderFilename(filename);
78 xmlTextReaderSetParserProp(reader, XML_PARSER_VALIDATE, 1);
81 * Process all nodes in sequence
83 ret = xmlTextReaderRead(reader);
86 ret = xmlTextReaderRead(reader);
90 * Done, cleanup and status
93 printf("%ld bytes consumed by parser\n", xmlTextReaderByteConsumed(reader));
94 xmlFreeTextReader(reader);
96 printf("%s : failed to parse\n", filename);
98 printf("%s : %d elements, %d attributes\n", filename, elem, attrs);
100 fprintf(stderr, "Unable to open %s\n", filename);
104 int main(int argc, char **argv) {
113 for (i = 1; i < argc ; i++) {
114 if ((!strcmp(argv[i], "-debug")) || (!strcmp(argv[i], "--debug")))
116 else if ((!strcmp(argv[i], "-dump")) || (!strcmp(argv[i], "--dump")))
118 else if ((!strcmp(argv[i], "-count")) || (!strcmp(argv[i], "--count")))
120 else if ((!strcmp(argv[i], "-consumed")) || (!strcmp(argv[i], "--consumed")))
122 else if ((!strcmp(argv[i], "-valid")) || (!strcmp(argv[i], "--valid")))
124 else if ((!strcmp(argv[i], "-noent")) ||
125 (!strcmp(argv[i], "--noent")))
128 if (noent != 0) xmlSubstituteEntitiesDefault(1);
129 for (i = 1; i < argc ; i++) {
130 if (argv[i][0] != '-') {
141 int main(int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED) {
142 printf("%s : xmlReader parser support not compiled in\n", argv[0]);
145 #endif /* LIBXML_READER_ENABLED */