Return to parse1.c CVS log | Up to [ELWIX - Embedded LightWeight unIX -] / embedaddon / libxml2 / doc / examples |
1.1 ! misho 1: /** ! 2: * section: Parsing ! 3: * synopsis: Parse an XML file to a tree and free it ! 4: * purpose: Demonstrate the use of xmlReadFile() to read an XML file ! 5: * into a tree and and xmlFreeDoc() to free the resulting tree ! 6: * usage: parse1 test1.xml ! 7: * test: parse1 test1.xml ! 8: * author: Daniel Veillard ! 9: * copy: see Copyright for the status of this software. ! 10: */ ! 11: ! 12: #include <stdio.h> ! 13: #include <libxml/parser.h> ! 14: #include <libxml/tree.h> ! 15: ! 16: /** ! 17: * example1Func: ! 18: * @filename: a filename or an URL ! 19: * ! 20: * Parse the resource and free the resulting tree ! 21: */ ! 22: static void ! 23: example1Func(const char *filename) { ! 24: xmlDocPtr doc; /* the resulting document tree */ ! 25: ! 26: doc = xmlReadFile(filename, NULL, 0); ! 27: if (doc == NULL) { ! 28: fprintf(stderr, "Failed to parse %s\n", filename); ! 29: return; ! 30: } ! 31: xmlFreeDoc(doc); ! 32: } ! 33: ! 34: int main(int argc, char **argv) { ! 35: if (argc != 2) ! 36: return(1); ! 37: ! 38: /* ! 39: * this initialize the library and check potential ABI mismatches ! 40: * between the version it was compiled for and the actual shared ! 41: * library used. ! 42: */ ! 43: LIBXML_TEST_VERSION ! 44: ! 45: example1Func(argv[1]); ! 46: ! 47: /* ! 48: * Cleanup function for the XML library. ! 49: */ ! 50: xmlCleanupParser(); ! 51: /* ! 52: * this is to debug memory for regression tests ! 53: */ ! 54: xmlMemoryDump(); ! 55: return(0); ! 56: }