xref: /PHP-8.2/ext/dom/tests/gh12616_3.phpt (revision 3167d076)
1--TEST--
2GH-12616 (DOM: Removing XMLNS namespace node results in invalid default: prefix)
3--EXTENSIONS--
4dom
5--FILE--
6<?php
7
8$doc = new DOMDocument();
9$doc->loadXML(
10    <<<XML
11    <container>
12      <child1 xmlns:x="http://symfony.com/schema/dic/services">
13        <x:foo x:bar=""/>
14        <x:foo x:bar=""/>
15      </child1>
16      <child2 xmlns:x="http://symfony.com/schema/dic/services">
17        <x:foo x:bar=""/>
18        <x:foo x:bar=""/>
19      </child2>
20    </container>
21    XML
22);
23
24$doc->documentElement->firstElementChild->removeAttributeNS('http://symfony.com/schema/dic/services', 'x');
25echo $doc->saveXML();
26
27$xpath = new DOMXPath($doc);
28
29echo "--- Namespaces of child1 ---\n";
30
31foreach ($xpath->query("/container/child1/namespace::*") as $ns) {
32    var_dump($ns);
33}
34
35echo "--- Namespaces of child1/foo (both nodes) ---\n";
36
37foreach ($xpath->query("/container/child1/foo/namespace::*") as $ns) {
38    var_dump($ns);
39}
40
41echo "--- Namespaces of child2 ---\n";
42
43foreach ($xpath->query("/container/child2/namespace::*") as $ns) {
44    var_dump($ns);
45}
46
47?>
48--EXPECT--
49<?xml version="1.0"?>
50<container>
51  <child1>
52    <foo bar=""/>
53    <foo bar=""/>
54  </child1>
55  <child2 xmlns:x="http://symfony.com/schema/dic/services">
56    <x:foo x:bar=""/>
57    <x:foo x:bar=""/>
58  </child2>
59</container>
60--- Namespaces of child1 ---
61object(DOMNameSpaceNode)#4 (8) {
62  ["nodeName"]=>
63  string(9) "xmlns:xml"
64  ["nodeValue"]=>
65  string(36) "http://www.w3.org/XML/1998/namespace"
66  ["nodeType"]=>
67  int(18)
68  ["prefix"]=>
69  string(3) "xml"
70  ["localName"]=>
71  string(3) "xml"
72  ["namespaceURI"]=>
73  string(36) "http://www.w3.org/XML/1998/namespace"
74  ["ownerDocument"]=>
75  string(22) "(object value omitted)"
76  ["parentNode"]=>
77  string(22) "(object value omitted)"
78}
79--- Namespaces of child1/foo (both nodes) ---
80object(DOMNameSpaceNode)#5 (8) {
81  ["nodeName"]=>
82  string(9) "xmlns:xml"
83  ["nodeValue"]=>
84  string(36) "http://www.w3.org/XML/1998/namespace"
85  ["nodeType"]=>
86  int(18)
87  ["prefix"]=>
88  string(3) "xml"
89  ["localName"]=>
90  string(3) "xml"
91  ["namespaceURI"]=>
92  string(36) "http://www.w3.org/XML/1998/namespace"
93  ["ownerDocument"]=>
94  string(22) "(object value omitted)"
95  ["parentNode"]=>
96  string(22) "(object value omitted)"
97}
98object(DOMNameSpaceNode)#8 (8) {
99  ["nodeName"]=>
100  string(9) "xmlns:xml"
101  ["nodeValue"]=>
102  string(36) "http://www.w3.org/XML/1998/namespace"
103  ["nodeType"]=>
104  int(18)
105  ["prefix"]=>
106  string(3) "xml"
107  ["localName"]=>
108  string(3) "xml"
109  ["namespaceURI"]=>
110  string(36) "http://www.w3.org/XML/1998/namespace"
111  ["ownerDocument"]=>
112  string(22) "(object value omitted)"
113  ["parentNode"]=>
114  string(22) "(object value omitted)"
115}
116--- Namespaces of child2 ---
117object(DOMNameSpaceNode)#9 (8) {
118  ["nodeName"]=>
119  string(9) "xmlns:xml"
120  ["nodeValue"]=>
121  string(36) "http://www.w3.org/XML/1998/namespace"
122  ["nodeType"]=>
123  int(18)
124  ["prefix"]=>
125  string(3) "xml"
126  ["localName"]=>
127  string(3) "xml"
128  ["namespaceURI"]=>
129  string(36) "http://www.w3.org/XML/1998/namespace"
130  ["ownerDocument"]=>
131  string(22) "(object value omitted)"
132  ["parentNode"]=>
133  string(22) "(object value omitted)"
134}
135object(DOMNameSpaceNode)#5 (8) {
136  ["nodeName"]=>
137  string(7) "xmlns:x"
138  ["nodeValue"]=>
139  string(38) "http://symfony.com/schema/dic/services"
140  ["nodeType"]=>
141  int(18)
142  ["prefix"]=>
143  string(1) "x"
144  ["localName"]=>
145  string(1) "x"
146  ["namespaceURI"]=>
147  string(38) "http://symfony.com/schema/dic/services"
148  ["ownerDocument"]=>
149  string(22) "(object value omitted)"
150  ["parentNode"]=>
151  string(22) "(object value omitted)"
152}
153