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