xref: /PHP-7.4/ext/simplexml/tests/004.phpt (revision 782352c5)
1--TEST--
2SimpleXML: CDATA
3--SKIPIF--
4<?php if (!extension_loaded("simplexml")) print "skip"; ?>
5--FILE--
6<?php
7
8$sxe = simplexml_load_string(<<<EOF
9<?xml version='1.0'?>
10<!DOCTYPE sxe SYSTEM "notfound.dtd">
11<sxe id="elem1">
12 Plain text.
13 <elem1 attr1='first'>
14  <!-- comment -->
15  <elem2>
16   <![CDATA[CDATA block]]>
17   <elem3>
18    <elem4>
19     <?test processing instruction ?>
20    </elem4>
21   </elem3>
22  </elem2>
23 </elem1>
24</sxe>
25EOF
26);
27
28var_dump($sxe);
29
30$elem1 = $sxe->elem1;
31$elem2 = $elem1->elem2;
32var_dump(trim((string)$elem2));
33
34?>
35===DONE===
36--EXPECTF--
37object(SimpleXMLElement)#%d (2) {
38  ["@attributes"]=>
39  array(1) {
40    ["id"]=>
41    string(5) "elem1"
42  }
43  ["elem1"]=>
44  object(SimpleXMLElement)#%d (3) {
45    ["@attributes"]=>
46    array(1) {
47      ["attr1"]=>
48      string(5) "first"
49    }
50    ["comment"]=>
51    object(SimpleXMLElement)#%d (0) {
52    }
53    ["elem2"]=>
54    object(SimpleXMLElement)#%d (1) {
55      ["elem3"]=>
56      object(SimpleXMLElement)#%d (1) {
57        ["elem4"]=>
58        object(SimpleXMLElement)#%d (1) {
59          ["test"]=>
60          object(SimpleXMLElement)#%d (0) {
61          }
62        }
63      }
64    }
65  }
66}
67string(11) "CDATA block"
68===DONE===
69