xref: /PHP-8.0/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");
6?>
7--FILE--
8<?php
9
10$xw = xmlwriter_open_memory();
11xmlwriter_set_indent($xw, TRUE);
12xmlwriter_set_indent_string($xw, '   ');
13xmlwriter_start_document($xw, '1.0', "UTF-8");
14xmlwriter_start_element($xw, 'root');
15xmlwriter_start_element_ns($xw, 'ns1', 'child1', 'urn:ns1');
16xmlwriter_start_attribute_ns($xw, 'ns1', 'att1', 'urn:ns1');
17xmlwriter_text($xw, 'a&b');
18xmlwriter_end_attribute($xw);
19xmlwriter_write_attribute($xw, 'att2', "double\" single'");
20xmlwriter_start_attribute_ns($xw, 'ns1', 'att2', 'urn:ns1');
21xmlwriter_text($xw, "<>\"'&");
22xmlwriter_end_attribute($xw);
23xmlwriter_write_element($xw, 'chars', "special characters: <>\"'&");
24xmlwriter_end_element($xw);
25xmlwriter_end_document($xw);
26// Force to write and empty the buffer
27$output = xmlwriter_flush($xw, true);
28print $output;
29?>
30--EXPECT--
31<?xml version="1.0" encoding="UTF-8"?>
32<root>
33   <ns1:child1 ns1:att1="a&amp;b" att2="double&quot; single'" ns1:att2="&lt;&gt;&quot;'&amp;" xmlns:ns1="urn:ns1">
34      <chars>special characters: &lt;&gt;&quot;'&amp;</chars>
35   </ns1:child1>
36</root>
37