xmlwriter_mem.php 858 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. dl('xmlwriter.so');
  3. $xw = xmlwriter_open_memory();
  4. xmlwriter_set_indent($xw, 1);
  5. $res = xmlwriter_set_indent_string($xw, ' ');
  6. xmlwriter_start_document($xw, '1.0', 'UTF-8');
  7. // A first element
  8. xmlwriter_start_element($xw, 'tag1');
  9. // Attribute 'att1' for element 'tag1'
  10. xmlwriter_start_attribute($xw, 'att1');
  11. xmlwriter_text($xw, 'valueofatt1');
  12. xmlwriter_end_attribute($xw);
  13. xmlwriter_text($xw, utf8_encode('This is a sample text, ä'));
  14. xmlwriter_end_element($xw); // tag1
  15. $res = xmlwriter_start_comment($xw);
  16. xmlwriter_text($xw, "Demo text comment");
  17. $res = xmlwriter_end_comment($xw);
  18. xmlwriter_end_document($xw);
  19. $out = xmlwriter_output_memory($xw, 0);
  20. echo $out;
  21. // flush the xml buffer using optional
  22. // flust argument, default is 1
  23. $out = xmlwriter_output_memory($xw, 1);
  24. echo $out;
  25. $out = xmlwriter_output_memory($xw);
  26. echo $out;