xref: /PHP-5.4/ext/xmlwriter/tests/009.phpt (revision 92b6f242)
1--TEST--
2XMLWriter: PI, Comment, CDATA
3--SKIPIF--
4<?php
5if (!extension_loaded("xmlwriter")) die("skip");
6if (!function_exists("xmlwriter_start_comment")) die("skip: libxml2 2.6.7+ required");
7?>
8--FILE--
9<?php
10/* $Id$ */
11/*
12Libxml 2.6.24 and up adds a new line after a processing instruction (PI)
13*/
14$xw = xmlwriter_open_memory();
15xmlwriter_set_indent($xw, TRUE);
16xmlwriter_start_document($xw, NULL, "UTF-8");
17xmlwriter_start_element($xw, 'root');
18xmlwriter_write_attribute($xw, 'id', 'elem1');
19xmlwriter_start_element($xw, 'elem1');
20xmlwriter_write_attribute($xw, 'attr1', 'first');
21xmlwriter_write_comment($xw, 'start PI');
22xmlwriter_start_element($xw, 'pi');
23xmlwriter_write_pi($xw, 'php', 'echo "hello world"; ');
24xmlwriter_end_element($xw);
25xmlwriter_start_element($xw, 'cdata');
26xmlwriter_start_cdata($xw);
27xmlwriter_text($xw, '<>&"');
28xmlwriter_end_cdata($xw);
29xmlwriter_end_element($xw);
30xmlwriter_end_element($xw);
31xmlwriter_end_element($xw);
32xmlwriter_end_document($xw);
33// Force to write and empty the buffer
34$output = xmlwriter_flush($xw, true);
35print $output;
36?>
37--EXPECTF--
38<?xml version="1.0" encoding="UTF-8"?>
39<root id="elem1">
40 <elem1 attr1="first">
41  <!--start PI-->
42  <pi><?php echo "hello world"; ?>%w</pi>
43  <cdata><![CDATA[<>&"]]></cdata>
44 </elem1>
45</root>
46