xref: /PHP-7.4/ext/xmlwriter/tests/OO_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 = new XMLWriter();
11$xw->openMemory();
12$xw->setIndent(TRUE);
13$xw->setIndentString('   ');
14$xw->startDocument('1.0', "UTF-8");
15$xw->startElement('root');
16$xw->startElementNS('ns1', 'child1', 'urn:ns1');
17$xw->startAttributeNS('ns1', 'att1', 'urn:ns1');
18$xw->text('a&b');
19$xw->endAttribute();
20$xw->writeAttribute('att2', "double\" single'");
21$xw->startAttributeNS('ns1', 'att2', 'urn:ns1');
22$xw->text("<>\"'&");
23$xw->endAttribute();
24$xw->writeElement('chars', "special characters: <>\"'&");
25$xw->endElement();
26$xw->endDocument();
27// Force to write and empty the buffer
28$output = $xw->flush(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