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