xref: /PHP-8.1/ext/xmlwriter/tests/OO_009.phpt (revision 74859783)
1--TEST--
2XMLWriter: PI, Comment, CDATA
3--EXTENSIONS--
4xmlwriter
5--FILE--
6<?php
7/*
8Libxml 2.6.24 and up adds a new line after a processing instruction (PI)
9*/
10$xw = new XMLWriter();
11$xw->openMemory();
12$xw->setIndent(TRUE);
13$xw->startDocument("1.0", "UTF-8");
14$xw->startElement('root');
15$xw->writeAttribute('id', 'elem1');
16$xw->startElement('elem1');
17$xw->writeAttribute('attr1', 'first');
18$xw->writeComment('start PI');
19$xw->startElement('pi');
20$xw->writePi('php', 'echo "hello world"; ');
21$xw->endElement();
22$xw->startElement('cdata');
23$xw->startCdata();
24$xw->text('<>&"');
25$xw->endCdata();
26$xw->endElement();
27$xw->endElement();
28$xw->endElement();
29$xw->endDocument();
30// Force to write and empty the buffer
31$output = $xw->flush(true);
32print $output;
33?>
34--EXPECTF--
35<?xml version="1.0" encoding="UTF-8"?>
36<root id="elem1">
37 <elem1 attr1="first">
38  <!--start PI-->
39  <pi><?php echo "hello world"; ?>%w</pi>
40  <cdata><![CDATA[<>&"]]></cdata>
41 </elem1>
42</root>
43