2
0

io2.pas 909 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. (**
  2. * section: InputOutput
  3. * synopsis: Output to char buffer
  4. * purpose: Demonstrate the use of xmlDocDumpMemory
  5. * to output document to a character buffer
  6. * usage: io2
  7. * test: io2 > io2.tmp ; diff io2.tmp io2.res ; rm -f io2.tmp
  8. * author: John Fleck
  9. * copy: see Copyright for the status of this software.
  10. *)
  11. program io2;
  12. {$mode objfpc}
  13. uses
  14. ctypes,
  15. xml2,
  16. exutils,
  17. SysUtils;
  18. var
  19. n: xmlNodePtr;
  20. doc: xmlDocPtr;
  21. xmlbuff: xmlCharPtr;
  22. buffersize: cint;
  23. begin
  24. (*
  25. * Create the document.
  26. *)
  27. doc := xmlNewDoc('1.0');
  28. n := xmlNewNode(nil, 'root');
  29. xmlNodeSetContent(n, 'content');
  30. xmlDocSetRootElement(doc, n);
  31. (*
  32. * Dump the document to a buffer and print it
  33. * for demonstration purposes.
  34. *)
  35. xmlDocDumpFormatMemory(doc, xmlbuff, buffersize, 1);
  36. printfn(xmlbuff);
  37. (*
  38. * Free associated memory.
  39. *)
  40. xmlFree(xmlbuff);
  41. xmlFreeDoc(doc);
  42. end.