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