|
| 1 | +--TEST-- |
| 2 | +GH-12616 (DOM: Removing XMLNS namespace node results in invalid default: prefix) |
| 3 | +--EXTENSIONS-- |
| 4 | +dom |
| 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'); |
| 25 | +echo $doc->saveXML(); |
| 26 | + |
| 27 | +$xpath = new DOMXPath($doc); |
| 28 | + |
| 29 | +echo "--- Namespaces of child1 ---\n"; |
| 30 | + |
| 31 | +foreach ($xpath->query("/container/child1/namespace::*") as $ns) { |
| 32 | + var_dump($ns); |
| 33 | +} |
| 34 | + |
| 35 | +echo "--- Namespaces of child1/foo (both nodes) ---\n"; |
| 36 | + |
| 37 | +foreach ($xpath->query("/container/child1/foo/namespace::*") as $ns) { |
| 38 | + var_dump($ns); |
| 39 | +} |
| 40 | + |
| 41 | +echo "--- Namespaces of child2 ---\n"; |
| 42 | + |
| 43 | +foreach ($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 --- |
| 61 | +object(DOMNameSpaceNode)#4 (10) { |
| 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 | + ["isConnected"]=> |
| 75 | + bool(true) |
| 76 | + ["ownerDocument"]=> |
| 77 | + string(22) "(object value omitted)" |
| 78 | + ["parentNode"]=> |
| 79 | + string(22) "(object value omitted)" |
| 80 | + ["parentElement"]=> |
| 81 | + string(22) "(object value omitted)" |
| 82 | +} |
| 83 | +--- Namespaces of child1/foo (both nodes) --- |
| 84 | +object(DOMNameSpaceNode)#5 (10) { |
| 85 | + ["nodeName"]=> |
| 86 | + string(9) "xmlns:xml" |
| 87 | + ["nodeValue"]=> |
| 88 | + string(36) "http://www.w3.org/XML/1998/namespace" |
| 89 | + ["nodeType"]=> |
| 90 | + int(18) |
| 91 | + ["prefix"]=> |
| 92 | + string(3) "xml" |
| 93 | + ["localName"]=> |
| 94 | + string(3) "xml" |
| 95 | + ["namespaceURI"]=> |
| 96 | + string(36) "http://www.w3.org/XML/1998/namespace" |
| 97 | + ["isConnected"]=> |
| 98 | + bool(true) |
| 99 | + ["ownerDocument"]=> |
| 100 | + string(22) "(object value omitted)" |
| 101 | + ["parentNode"]=> |
| 102 | + string(22) "(object value omitted)" |
| 103 | + ["parentElement"]=> |
| 104 | + string(22) "(object value omitted)" |
| 105 | +} |
| 106 | +object(DOMNameSpaceNode)#8 (10) { |
| 107 | + ["nodeName"]=> |
| 108 | + string(9) "xmlns:xml" |
| 109 | + ["nodeValue"]=> |
| 110 | + string(36) "http://www.w3.org/XML/1998/namespace" |
| 111 | + ["nodeType"]=> |
| 112 | + int(18) |
| 113 | + ["prefix"]=> |
| 114 | + string(3) "xml" |
| 115 | + ["localName"]=> |
| 116 | + string(3) "xml" |
| 117 | + ["namespaceURI"]=> |
| 118 | + string(36) "http://www.w3.org/XML/1998/namespace" |
| 119 | + ["isConnected"]=> |
| 120 | + bool(true) |
| 121 | + ["ownerDocument"]=> |
| 122 | + string(22) "(object value omitted)" |
| 123 | + ["parentNode"]=> |
| 124 | + string(22) "(object value omitted)" |
| 125 | + ["parentElement"]=> |
| 126 | + string(22) "(object value omitted)" |
| 127 | +} |
| 128 | +--- Namespaces of child2 --- |
| 129 | +object(DOMNameSpaceNode)#9 (10) { |
| 130 | + ["nodeName"]=> |
| 131 | + string(9) "xmlns:xml" |
| 132 | + ["nodeValue"]=> |
| 133 | + string(36) "http://www.w3.org/XML/1998/namespace" |
| 134 | + ["nodeType"]=> |
| 135 | + int(18) |
| 136 | + ["prefix"]=> |
| 137 | + string(3) "xml" |
| 138 | + ["localName"]=> |
| 139 | + string(3) "xml" |
| 140 | + ["namespaceURI"]=> |
| 141 | + string(36) "http://www.w3.org/XML/1998/namespace" |
| 142 | + ["isConnected"]=> |
| 143 | + bool(true) |
| 144 | + ["ownerDocument"]=> |
| 145 | + string(22) "(object value omitted)" |
| 146 | + ["parentNode"]=> |
| 147 | + string(22) "(object value omitted)" |
| 148 | + ["parentElement"]=> |
| 149 | + string(22) "(object value omitted)" |
| 150 | +} |
| 151 | +object(DOMNameSpaceNode)#5 (10) { |
| 152 | + ["nodeName"]=> |
| 153 | + string(7) "xmlns:x" |
| 154 | + ["nodeValue"]=> |
| 155 | + string(38) "http://symfony.com/schema/dic/services" |
| 156 | + ["nodeType"]=> |
| 157 | + int(18) |
| 158 | + ["prefix"]=> |
| 159 | + string(1) "x" |
| 160 | + ["localName"]=> |
| 161 | + string(1) "x" |
| 162 | + ["namespaceURI"]=> |
| 163 | + string(38) "http://symfony.com/schema/dic/services" |
| 164 | + ["isConnected"]=> |
| 165 | + bool(true) |
| 166 | + ["ownerDocument"]=> |
| 167 | + string(22) "(object value omitted)" |
| 168 | + ["parentNode"]=> |
| 169 | + string(22) "(object value omitted)" |
| 170 | + ["parentElement"]=> |
| 171 | + string(22) "(object value omitted)" |
| 172 | +} |
0 commit comments