xref: /php-src/ext/xmlwriter/tests/OO_007.phpt (revision 74859783)
1--TEST--
2XMLWriter: libxml2 XML Writer, Elements & Attributes
3--EXTENSIONS--
4xmlwriter
5--FILE--
6<?php
7
8$xw = new XMLWriter();
9$xw->openMemory();
10$xw->setIndent(TRUE);
11$xw->setIndentString('   ');
12$xw->startDocument('1.0', "UTF-8");
13$xw->startElement('root');
14$xw->startElementNS('ns1', 'child1', 'urn:ns1');
15$xw->startAttributeNS('ns1', 'att1', 'urn:ns1');
16$xw->text('a&b');
17$xw->endAttribute();
18$xw->writeAttribute('att2', "double\" single'");
19$xw->startAttributeNS('ns1', 'att2', 'urn:ns1');
20$xw->text("<>\"'&");
21$xw->endAttribute();
22$xw->writeElement('chars', "special characters: <>\"'&");
23$xw->endElement();
24$xw->endDocument();
25// Force to write and empty the buffer
26$output = $xw->flush(true);
27print $output;
28?>
29--EXPECT--
30<?xml version="1.0" encoding="UTF-8"?>
31<root>
32   <ns1:child1 ns1:att1="a&amp;b" att2="double&quot; single'" ns1:att2="&lt;&gt;&quot;'&amp;" xmlns:ns1="urn:ns1">
33      <chars>special characters: &lt;&gt;&quot;'&amp;</chars>
34   </ns1:child1>
35</root>
36