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