1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
|
--TEST--
DOM\Element::getDescendantNamespaces()
--EXTENSIONS--
dom
--FILE--
<?php
function dump($dom, $name) {
echo "\n=== $name ===\n";
$list = $dom->getElementsByTagName($name)[0]->getDescendantNamespaces();
foreach ($list as $entry) {
echo "prefix: ";
var_dump($entry->prefix);
echo "namespaceURI: ";
var_dump($entry->namespaceURI);
echo "element->nodeName: ";
var_dump($entry->element->nodeName);
echo "---\n";
}
}
$dom = DOM\XMLDocument::createFromString(<<<XML
<root xmlns="urn:a">
<child xmlns="">
<c:child xmlns:c="urn:c"/>
</child>
<b:sibling xmlns:b="urn:b" xmlns:d="urn:d" d:foo="bar">
<d:child xmlns:d="urn:d2"/>
</b:sibling>
</root>
XML);
dump($dom, 'c:child');
dump($dom, 'child');
dump($dom, 'b:sibling');
dump($dom, 'd:child');
dump($dom, 'root');
?>
--EXPECT--
=== c:child ===
prefix: string(1) "c"
namespaceURI: string(5) "urn:c"
element->nodeName: string(7) "c:child"
---
=== child ===
prefix: string(1) "c"
namespaceURI: string(5) "urn:c"
element->nodeName: string(7) "c:child"
---
=== b:sibling ===
prefix: NULL
namespaceURI: string(5) "urn:a"
element->nodeName: string(9) "b:sibling"
---
prefix: string(1) "b"
namespaceURI: string(5) "urn:b"
element->nodeName: string(9) "b:sibling"
---
prefix: string(1) "d"
namespaceURI: string(5) "urn:d"
element->nodeName: string(9) "b:sibling"
---
prefix: NULL
namespaceURI: string(5) "urn:a"
element->nodeName: string(7) "d:child"
---
prefix: string(1) "b"
namespaceURI: string(5) "urn:b"
element->nodeName: string(7) "d:child"
---
prefix: string(1) "d"
namespaceURI: string(6) "urn:d2"
element->nodeName: string(7) "d:child"
---
=== d:child ===
prefix: NULL
namespaceURI: string(5) "urn:a"
element->nodeName: string(7) "d:child"
---
prefix: string(1) "b"
namespaceURI: string(5) "urn:b"
element->nodeName: string(7) "d:child"
---
prefix: string(1) "d"
namespaceURI: string(6) "urn:d2"
element->nodeName: string(7) "d:child"
---
=== root ===
prefix: NULL
namespaceURI: string(5) "urn:a"
element->nodeName: string(4) "root"
---
prefix: string(1) "c"
namespaceURI: string(5) "urn:c"
element->nodeName: string(7) "c:child"
---
prefix: NULL
namespaceURI: string(5) "urn:a"
element->nodeName: string(9) "b:sibling"
---
prefix: string(1) "b"
namespaceURI: string(5) "urn:b"
element->nodeName: string(9) "b:sibling"
---
prefix: string(1) "d"
namespaceURI: string(5) "urn:d"
element->nodeName: string(9) "b:sibling"
---
prefix: NULL
namespaceURI: string(5) "urn:a"
element->nodeName: string(7) "d:child"
---
prefix: string(1) "b"
namespaceURI: string(5) "urn:b"
element->nodeName: string(7) "d:child"
---
prefix: string(1) "d"
namespaceURI: string(6) "urn:d2"
element->nodeName: string(7) "d:child"
---
|