xref: /PHP-7.4/ext/xmlwriter/tests/OO_009.phpt (revision 782352c5)
1--TEST--
2XMLWriter: PI, Comment, CDATA
3--SKIPIF--
4<?php
5if (!extension_loaded("xmlwriter")) die("skip");
6?>
7--FILE--
8<?php
9/*
10Libxml 2.6.24 and up adds a new line after a processing instruction (PI)
11*/
12$xw = new XMLWriter();
13$xw->openMemory();
14$xw->setIndent(TRUE);
15$xw->startDocument("1.0", "UTF-8");
16$xw->startElement('root');
17$xw->writeAttribute('id', 'elem1');
18$xw->startElement('elem1');
19$xw->writeAttribute('attr1', 'first');
20$xw->writeComment('start PI');
21$xw->startElement('pi');
22$xw->writePi('php', 'echo "hello world"; ');
23$xw->endElement();
24$xw->startElement('cdata');
25$xw->startCdata();
26$xw->text('<>&"');
27$xw->endCdata();
28$xw->endElement();
29$xw->endElement();
30$xw->endElement();
31$xw->endDocument();
32// Force to write and empty the buffer
33$output = $xw->flush(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