ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

testReader.c
Go to the documentation of this file.
00001 /*
00002  * testSAX.c : a small tester program for parsing using the SAX API.
00003  *
00004  * See Copyright for the status of this software.
00005  *
00006  * daniel@veillard.com
00007  */
00008 
00009 #include "libxml.h"
00010 
00011 #ifdef LIBXML_READER_ENABLED
00012 #include <string.h>
00013 #include <stdarg.h>
00014 
00015 #ifdef HAVE_SYS_TYPES_H
00016 #include <sys/types.h>
00017 #endif
00018 #ifdef HAVE_SYS_STAT_H
00019 #include <sys/stat.h>
00020 #endif
00021 #ifdef HAVE_FCNTL_H
00022 #include <fcntl.h>
00023 #endif
00024 #ifdef HAVE_UNISTD_H
00025 #include <unistd.h>
00026 #endif
00027 #ifdef HAVE_STDLIB_H
00028 #include <stdlib.h>
00029 #endif
00030 #ifdef HAVE_STRING_H
00031 #include <string.h>
00032 #endif
00033 
00034 
00035 #include <libxml/xmlreader.h>
00036 
00037 static int debug = 0;
00038 static int dump = 0;
00039 static int noent = 0;
00040 static int count = 0;
00041 static int valid = 0;
00042 static int consumed = 0;
00043 
00044 static void usage(const char *progname) {
00045     printf("Usage : %s [options] XMLfiles ...\n", progname);
00046     printf("\tParse the XML files using the xmlTextReader API\n");
00047     printf("\t --count: count the number of attribute and elements\n");
00048     printf("\t --valid: validate the document\n");
00049     printf("\t --consumed: count the number of bytes consumed\n");
00050     exit(1);
00051 }
00052 static int elem, attrs;
00053 
00054 static void processNode(xmlTextReaderPtr reader) {
00055     int type;
00056 
00057     type = xmlTextReaderNodeType(reader);
00058     if (count) {
00059     if (type == 1) {
00060         elem++;
00061         attrs += xmlTextReaderAttributeCount(reader);
00062     }
00063     }
00064 }
00065 
00066 static void handleFile(const char *filename) {
00067     xmlTextReaderPtr reader;
00068     int ret;
00069 
00070     if (count) {
00071     elem = 0;
00072     attrs = 0;
00073     }
00074 
00075     reader = xmlNewTextReaderFilename(filename);
00076     if (reader != NULL) {
00077     if (valid)
00078         xmlTextReaderSetParserProp(reader, XML_PARSER_VALIDATE, 1);
00079 
00080     /*
00081      * Process all nodes in sequence
00082      */
00083     ret = xmlTextReaderRead(reader);
00084     while (ret == 1) {
00085         processNode(reader);
00086         ret = xmlTextReaderRead(reader);
00087     }
00088 
00089     /*
00090      * Done, cleanup and status
00091      */
00092     if (consumed)
00093         printf("%ld bytes consumed by parser\n", xmlTextReaderByteConsumed(reader));
00094     xmlFreeTextReader(reader);
00095     if (ret != 0) {
00096         printf("%s : failed to parse\n", filename);
00097     } else if (count)
00098         printf("%s : %d elements, %d attributes\n", filename, elem, attrs);
00099     } else {
00100     fprintf(stderr, "Unable to open %s\n", filename);
00101     }
00102 }
00103 
00104 int main(int argc, char **argv) {
00105     int i;
00106     int files = 0;
00107 
00108     if (argc <= 1) {
00109     usage(argv[0]);
00110     return(1);
00111     }
00112     LIBXML_TEST_VERSION
00113     for (i = 1; i < argc ; i++) {
00114     if ((!strcmp(argv[i], "-debug")) || (!strcmp(argv[i], "--debug")))
00115         debug++;
00116     else if ((!strcmp(argv[i], "-dump")) || (!strcmp(argv[i], "--dump")))
00117         dump++;
00118     else if ((!strcmp(argv[i], "-count")) || (!strcmp(argv[i], "--count")))
00119         count++;
00120     else if ((!strcmp(argv[i], "-consumed")) || (!strcmp(argv[i], "--consumed")))
00121         consumed++;
00122     else if ((!strcmp(argv[i], "-valid")) || (!strcmp(argv[i], "--valid")))
00123         valid++;
00124     else if ((!strcmp(argv[i], "-noent")) ||
00125              (!strcmp(argv[i], "--noent")))
00126         noent++;
00127     }
00128     if (noent != 0) xmlSubstituteEntitiesDefault(1);
00129     for (i = 1; i < argc ; i++) {
00130     if (argv[i][0] != '-') {
00131         handleFile(argv[i]);
00132         files ++;
00133     }
00134     }
00135     xmlCleanupParser();
00136     xmlMemoryDump();
00137 
00138     return(0);
00139 }
00140 #else
00141 int main(int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED) {
00142     printf("%s : xmlReader parser support not compiled in\n", argv[0]);
00143     return(0);
00144 }
00145 #endif /* LIBXML_READER_ENABLED */

Generated on Sat May 26 2012 04:33:32 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.