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