xref: /php-src/ext/xmlwriter/tests/007.phpt (revision 74859783)
1--TEST--
2XMLWriter: libxml2 XML Writer, Elements & Attributes
3--EXTENSIONS--
4xmlwriter
5--FILE--
6<?php
7
8$xw = xmlwriter_open_memory();
9xmlwriter_set_indent($xw, TRUE);
10xmlwriter_set_indent_string($xw, '   ');
11xmlwriter_start_document($xw, '1.0', "UTF-8");
12xmlwriter_start_element($xw, 'root');
13xmlwriter_start_element_ns($xw, 'ns1', 'child1', 'urn:ns1');
14xmlwriter_start_attribute_ns($xw, 'ns1', 'att1', 'urn:ns1');
15xmlwriter_text($xw, 'a&b');
16xmlwriter_end_attribute($xw);
17xmlwriter_write_attribute($xw, 'att2', "double\" single'");
18xmlwriter_start_attribute_ns($xw, 'ns1', 'att2', 'urn:ns1');
19xmlwriter_text($xw, "<>\"'&");
20xmlwriter_end_attribute($xw);
21xmlwriter_write_element($xw, 'chars', "special characters: <>\"'&");
22xmlwriter_end_element($xw);
23xmlwriter_end_document($xw);
24// Force to write and empty the buffer
25$output = xmlwriter_flush($xw, true);
26print $output;
27?>
28--EXPECT--
29<?xml version="1.0" encoding="UTF-8"?>
30<root>
31   <ns1:child1 ns1:att1="a&amp;b" att2="double&quot; single'" ns1:att2="&lt;&gt;&quot;'&amp;" xmlns:ns1="urn:ns1">
32      <chars>special characters: &lt;&gt;&quot;'&amp;</chars>
33   </ns1:child1>
34</root>
35