xref: /PHP-7.3/ext/simplexml/tests/025.phpt (revision ded3d984)
1--TEST--
2SimpleXML: getting namespaces
3--SKIPIF--
4<?php if (!extension_loaded("simplexml")) print "skip"; ?>
5--FILE--
6<?php
7
8$xml =<<<EOF
9<?xml version='1.0'?>
10<xhtml:html xmlns:html='http://www.w3.org/1999/xhtml' xmlns:xhtml='http://www.w3.org/TR/REC-html40'>
11<xhtml:head><xhtml:title xmlns:xhtml='http://www.w3.org/TR/REC-html401'>bla</xhtml:title></xhtml:head>
12<xhtml:body html:title="b">
13<html:h1>bla</html:h1>
14<foo:bar xmlns:foo='foobar' xmlns:baz='foobarbaz'/>
15</xhtml:body>
16</xhtml:html>
17EOF;
18
19$sxe = simplexml_load_string($xml);
20
21var_dump($sxe->getNamespaces());
22var_dump($sxe->getNamespaces(true));
23var_dump($sxe->getDocNamespaces());
24var_dump($sxe->getDocNamespaces(true));
25
26$xml =<<<EOF
27<?xml version='1.0'?>
28<html xmlns='http://www.w3.org/1999/xhtml'>
29<head><title xmlns='http://www.w3.org/TR/REC-html40'>bla</title></head>
30</html>
31EOF;
32
33$sxe = simplexml_load_string($xml);
34
35var_dump($sxe->getNamespaces());
36var_dump($sxe->getDocNamespaces());
37
38$xml =<<<EOF
39<?xml version='1.0'?>
40<root/>
41EOF;
42
43$sxe = simplexml_load_string($xml);
44
45var_dump($sxe->getNamespaces());
46var_dump($sxe->getDocNamespaces());
47
48?>
49===DONE===
50<?php exit(0); ?>
51--EXPECT--
52array(1) {
53  ["xhtml"]=>
54  string(31) "http://www.w3.org/TR/REC-html40"
55}
56array(3) {
57  ["xhtml"]=>
58  string(31) "http://www.w3.org/TR/REC-html40"
59  ["html"]=>
60  string(28) "http://www.w3.org/1999/xhtml"
61  ["foo"]=>
62  string(6) "foobar"
63}
64array(2) {
65  ["html"]=>
66  string(28) "http://www.w3.org/1999/xhtml"
67  ["xhtml"]=>
68  string(31) "http://www.w3.org/TR/REC-html40"
69}
70array(4) {
71  ["html"]=>
72  string(28) "http://www.w3.org/1999/xhtml"
73  ["xhtml"]=>
74  string(31) "http://www.w3.org/TR/REC-html40"
75  ["foo"]=>
76  string(6) "foobar"
77  ["baz"]=>
78  string(9) "foobarbaz"
79}
80array(1) {
81  [""]=>
82  string(28) "http://www.w3.org/1999/xhtml"
83}
84array(1) {
85  [""]=>
86  string(28) "http://www.w3.org/1999/xhtml"
87}
88array(0) {
89}
90array(0) {
91}
92===DONE===
93