xref: /PHP-8.0/ext/simplexml/tests/004.phpt (revision a555cc0b)
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--EXPECTF--
36object(SimpleXMLElement)#%d (2) {
37  ["@attributes"]=>
38  array(1) {
39    ["id"]=>
40    string(5) "elem1"
41  }
42  ["elem1"]=>
43  object(SimpleXMLElement)#%d (3) {
44    ["@attributes"]=>
45    array(1) {
46      ["attr1"]=>
47      string(5) "first"
48    }
49    ["comment"]=>
50    object(SimpleXMLElement)#%d (0) {
51    }
52    ["elem2"]=>
53    object(SimpleXMLElement)#%d (1) {
54      ["elem3"]=>
55      object(SimpleXMLElement)#%d (1) {
56        ["elem4"]=>
57        object(SimpleXMLElement)#%d (1) {
58          ["test"]=>
59          object(SimpleXMLElement)#%d (0) {
60          }
61        }
62      }
63    }
64  }
65}
66string(11) "CDATA block"
67