xref: /PHP-8.1/ext/simplexml/tests/025.phpt (revision 7f2f0c00)
1--TEST--
2SimpleXML: getting namespaces
3--EXTENSIONS--
4simplexml
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--EXPECT--
50array(1) {
51  ["xhtml"]=>
52  string(31) "http://www.w3.org/TR/REC-html40"
53}
54array(3) {
55  ["xhtml"]=>
56  string(31) "http://www.w3.org/TR/REC-html40"
57  ["html"]=>
58  string(28) "http://www.w3.org/1999/xhtml"
59  ["foo"]=>
60  string(6) "foobar"
61}
62array(2) {
63  ["html"]=>
64  string(28) "http://www.w3.org/1999/xhtml"
65  ["xhtml"]=>
66  string(31) "http://www.w3.org/TR/REC-html40"
67}
68array(4) {
69  ["html"]=>
70  string(28) "http://www.w3.org/1999/xhtml"
71  ["xhtml"]=>
72  string(31) "http://www.w3.org/TR/REC-html40"
73  ["foo"]=>
74  string(6) "foobar"
75  ["baz"]=>
76  string(9) "foobarbaz"
77}
78array(1) {
79  [""]=>
80  string(28) "http://www.w3.org/1999/xhtml"
81}
82array(1) {
83  [""]=>
84  string(28) "http://www.w3.org/1999/xhtml"
85}
86array(0) {
87}
88array(0) {
89}
90