1<?php
2dl('xmlwriter.so');
3
4$xw = xmlwriter_open_uri('./a.xml');
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_write_comment($xw, 'this is a comment.');
19
20// Start a child element
21xmlwriter_start_element($xw, 'tag11');
22xmlwriter_text($xw, utf8_encode('This is a sample text, ä'));
23xmlwriter_end_element($xw); // tag11
24
25xmlwriter_end_element($xw); // tag1
26
27
28// CDATA
29xmlwriter_start_element($xw, 'testc');
30xmlwriter_write_cdata($xw, "This is a cdata content");
31xmlwriter_end_element($xw); // testctag
32
33xmlwriter_start_element($xw, 'testc');
34xmlwriter_start_cdata($xw);
35xmlwriter_text($xw, "test cdata2");
36xmlwriter_end_cdata($xw);
37xmlwriter_end_element($xw); // testctag
38
39// A processing instruction
40xmlwriter_start_pi($xw, 'php');
41xmlwriter_text($xw, '$foo=2;echo $foo;');
42xmlwriter_end_pi($xw);
43
44xmlwriter_end_document($xw);
45