parse3.pas 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. (**
  2. * section: Parsing
  3. * synopsis: Parse an XML document in memory to a tree and free it
  4. * purpose: Demonstrate the use of xmlReadMemory() to read an XML file
  5. * into a tree and xmlFreeDoc() to free the resulting tree
  6. * usage: parse3
  7. * test: parse3
  8. * author: Daniel Veillard
  9. * copy: see Copyright for the status of this software.
  10. *)
  11. program parse3;
  12. {$mode objfpc}
  13. uses
  14. xml2,
  15. exutils;
  16. const
  17. document = '<doc/>';
  18. (**
  19. * example3Func:
  20. * @content: the content of the document
  21. * @length: the length in bytes
  22. *
  23. * Parse the in memory document and free the resulting tree
  24. *)
  25. procedure example3Func(const content: PAnsiChar; length: Integer);
  26. var
  27. doc: xmlDocPtr; (* the resulting document tree *)
  28. begin
  29. (*
  30. * The document being in memory, it have no base per RFC 2396,
  31. * and the "noname.xml" argument will serve as its base.
  32. *)
  33. doc := xmlReadMemory(content, length, 'noname.xml', Nil, 0);
  34. if doc = Nil then
  35. begin
  36. printfn('Failed to parse document');
  37. Exit;
  38. end;
  39. xmlFreeDoc(doc);
  40. end;
  41. begin
  42. (*
  43. * this initialize the library and check potential ABI mismatches
  44. * between the version it was compiled for and the actual shared
  45. * library used.
  46. *)
  47. LIBXML_TEST_VERSION;
  48. example3Func(document, 6);
  49. (*
  50. * Cleanup function for the XML library.
  51. *)
  52. xmlCleanupParser();
  53. (*
  54. * this is to debug memory for regression tests
  55. *)
  56. xmlMemoryDump();
  57. end.