xref: /PHP-7.3/ext/xmlwriter/tests/009.phpt (revision 782352c5)
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/*
11Libxml 2.6.24 and up adds a new line after a processing instruction (PI)
12*/
13$xw = xmlwriter_open_memory();
14xmlwriter_set_indent($xw, TRUE);
15xmlwriter_start_document($xw, NULL, "UTF-8");
16xmlwriter_start_element($xw, 'root');
17xmlwriter_write_attribute($xw, 'id', 'elem1');
18xmlwriter_start_element($xw, 'elem1');
19xmlwriter_write_attribute($xw, 'attr1', 'first');
20xmlwriter_write_comment($xw, 'start PI');
21xmlwriter_start_element($xw, 'pi');
22xmlwriter_write_pi($xw, 'php', 'echo "hello world"; ');
23xmlwriter_end_element($xw);
24xmlwriter_start_element($xw, 'cdata');
25xmlwriter_start_cdata($xw);
26xmlwriter_text($xw, '<>&"');
27xmlwriter_end_cdata($xw);
28xmlwriter_end_element($xw);
29xmlwriter_end_element($xw);
30xmlwriter_end_element($xw);
31xmlwriter_end_document($xw);
32// Force to write and empty the buffer
33$output = xmlwriter_flush($xw, true);
34print $output;
35?>
36--EXPECTF--
37<?xml version="1.0" encoding="UTF-8"?>
38<root id="elem1">
39 <elem1 attr1="first">
40  <!--start PI-->
41  <pi><?php echo "hello world"; ?>%w</pi>
42  <cdata><![CDATA[<>&"]]></cdata>
43 </elem1>
44</root>
45