parse1.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. #include <stdio.h>
  12. #include <libxml/parser.h>
  13. #include <libxml/tree.h>
  14. /**
  15. * example1Func:
  16. * @filename: a filename or an URL
  17. *
  18. * Parse the resource and free the resulting tree
  19. */
  20. static void
  21. example1Func(const char *filename) {
  22. xmlDocPtr doc; /* the resulting document tree */
  23. doc = xmlReadFile(filename, NULL, 0);
  24. if (doc == NULL) {
  25. fprintf(stderr, "Failed to parse %s\n", filename);
  26. return;
  27. }
  28. xmlFreeDoc(doc);
  29. }
  30. int main(int argc, char **argv) {
  31. if (argc != 2)
  32. return(1);
  33. /*
  34. * this initialize the library and check potential ABI mismatches
  35. * between the version it was compiled for and the actual shared
  36. * library used.
  37. */
  38. LIBXML_TEST_VERSION
  39. example1Func(argv[1]);
  40. /*
  41. * Cleanup function for the XML library.
  42. */
  43. xmlCleanupParser();
  44. /*
  45. * this is to debug memory for regression tests
  46. */
  47. xmlMemoryDump();
  48. return(0);
  49. }