- Main Page
- Namespaces
- Classes
- Files
- Related Pages

# /Users/fpy/titan-1-5-MBARI/Mers/Utils/Io/Xml/Stream/Libxml2/reader1.c

    00001
    00014 #include <stdio.h>
    00015 #include <libxml/xmlreader.h>
    00016
    00017 #ifdef LIBXML_READER_ENABLED
    00018
    00025 static void
    00026 processNode(xmlTextReaderPtr reader) {
    00027     const xmlChar *name, *value;
    00028
    00029     name = xmlTextReaderConstName(reader);
    00030     if (name == NULL)
    00031         name = BAD_CAST "--";
    00032
    00033     value = xmlTextReaderConstValue(reader);
    00034
    00035     printf("%d %d %s %d %d",
    00036             xmlTextReaderDepth(reader),
    00037             xmlTextReaderNodeType(reader),
    00038             name,
    00039             xmlTextReaderIsEmptyElement(reader),
    00040             xmlTextReaderHasValue(reader));
    00041     if (value == NULL)
    00042         printf("\n");
    00043     else {
    00044         if (xmlStrlen(value) > 40)
    00045             printf(" %.40s...\n", value);
    00046         else
    00047             printf(" %s\n", value);
    00048     }
    00049 }
    00050
    00057 static void
    00058 streamFile(const char *filename) {
    00059     xmlTextReaderPtr reader;
    00060     int ret;
    00061
    00062     reader = xmlReaderForFile(filename, NULL, 0);
    00063     if (reader != NULL) {
    00064         ret = xmlTextReaderRead(reader);
    00065         while (ret == 1) {
    00066             processNode(reader);
    00067             ret = xmlTextReaderRead(reader);
    00068         }
    00069         xmlFreeTextReader(reader);
    00070         if (ret != 0) {
    00071             fprintf(stderr, "%s : failed to parse\n", filename);
    00072         }
    00073     } else {
    00074         fprintf(stderr, "Unable to open %s\n", filename);
    00075     }
    00076 }
    00077
    00078 int main(int argc, char **argv) {
    00079     if (argc != 2)
    00080         return(1);
    00081
    00082     /*
    00083      * this initialize the library and check potential ABI mismatches
    00084      * between the version it was compiled for and the actual shared
    00085      * library used.
    00086      */
    00087     LIBXML_TEST_VERSION
    00088
    00089     streamFile(argv[1]);
    00090
    00091     /*
    00092      * Cleanup function for the XML library.
    00093      */
    00094     xmlCleanupParser();
    00095     /*
    00096      * this is to debug memory for regression tests
    00097      */
    00098     xmlMemoryDump();
    00099     return(0);
    00100 }
    00101
    00102 #else
    00103 int main(void) {
    00104     fprintf(stderr, "XInclude support not compiled in\n");
    00105     exit(1);
    00106 }
    00107 #endif