parse1.pas 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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 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. program parse1;
  12. {$mode objfpc}
  13. uses
  14. xml2,
  15. exutils;
  16. {**
  17. * example1Func:
  18. * @filename: a filename or an URL
  19. *
  20. * Parse the resource and free the resulting tree
  21. *}
  22. procedure example1Func(const filename: PAnsiChar);
  23. var
  24. doc: xmlDocPtr; (* the resulting document tree *)
  25. begin
  26. doc := xmlReadFile(filename, nil, 0);
  27. if (doc = nil) then
  28. begin
  29. printfn('Failed to parse %s', [filename]);
  30. Exit;
  31. end;
  32. xmlFreeDoc(doc);
  33. end;
  34. begin
  35. if ParamCount <> 1 then
  36. Halt(1);
  37. (*
  38. * this initialize the library and check potential ABI mismatches
  39. * between the version it was compiled for and the actual shared
  40. * library used.
  41. *)
  42. LIBXML_TEST_VERSION;
  43. example1Func(PAnsiChar(ParamStr(1)));
  44. (*
  45. * Cleanup function for the XML library.
  46. *)
  47. xmlCleanupParser();
  48. (*
  49. * this is to debug memory for regression tests
  50. *)
  51. xmlMemoryDump();
  52. end.