xref: /PHP-5.4/ext/xmlwriter/tests/OO_007.phpt (revision a61d4453)
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/* $Id$ */
11
12$xw = new XMLWriter();
13$xw->openMemory();
14$xw->setIndent(TRUE);
15$xw->setIndentString('   ');
16$xw->startDocument('1.0', "UTF-8");
17$xw->startElement('root');
18$xw->startElementNS('ns1', 'child1', 'urn:ns1');
19$xw->startAttributeNS('ns1', 'att1', 'urn:ns1');
20$xw->text('a&b');
21$xw->endAttribute();
22$xw->writeAttribute('att2', "double\" single'");
23$xw->startAttributeNS('ns1', 'att2', 'urn:ns1');
24$xw->text("<>\"'&");
25$xw->endAttribute();
26$xw->writeElement('chars', "special characters: <>\"'&");
27$xw->endElement();
28$xw->endDocument();
29// Force to write and empty the buffer
30$output = $xw->flush(true);
31print $output;
32?>
33--EXPECT--
34<?xml version="1.0" encoding="UTF-8"?>
35<root>
36   <ns1:child1 ns1:att1="a&amp;b" att2="double&quot; single'" ns1:att2="&lt;&gt;&quot;'&amp;" xmlns:ns1="urn:ns1">
37      <chars>special characters: &lt;&gt;&quot;'&amp;</chars>
38   </ns1:child1>
39</root>
40