1--TEST--
2DOMDocument::getElementsByTagNameNS() match any namespace
3--EXTENSIONS--
4dom
5--FILE--
6<?php
7
8/* Sample document taken from https://www.php.net/manual/en/domdocument.getelementsbytagname.php */
9$xml = <<<EOD
10<?xml version="1.0" ?>
11<chapter xmlns:xi="http://www.w3.org/2001/XInclude">
12<title>Books of the other guy..</title>
13<para>
14 <xi:include href="book.xml">
15  <xi:fallback>
16   <error>xinclude: book.xml not found</error>
17  </xi:fallback>
18 </xi:include>
19 <include>
20  This is another namespace
21 </include>
22</para>
23</chapter>
24EOD;
25$dom = new DOMDocument;
26
27// load the XML string defined above
28$dom->loadXML($xml);
29
30function test($namespace, $local) {
31    global $dom;
32    $namespace_str = $namespace !== NULL ? "'$namespace'" : "null";
33    echo "-- getElementsByTagNameNS($namespace_str, '$local') --\n";
34    foreach ($dom->getElementsByTagNameNS($namespace, $local) as $element) {
35        echo 'local name: \'', $element->localName, '\', prefix: \'', $element->prefix, "'\n";
36    }
37}
38
39// Should *also* include objects even without a namespace
40test(null, '*');
41// Should *also* include objects even without a namespace
42test('*', '*');
43// Should *only* include objects without a namespace
44test('', '*');
45// Should *only* include objects with the specified namespace
46test('http://www.w3.org/2001/XInclude', '*');
47// Should not give any output
48test('', 'fallback');
49// Should not give any output, because the null namespace is the same as the empty namespace
50test(null, 'fallback');
51// Should only output the include from the empty namespace
52test(null, 'include');
53
54?>
55--EXPECT--
56-- getElementsByTagNameNS(null, '*') --
57local name: 'chapter', prefix: ''
58local name: 'title', prefix: ''
59local name: 'para', prefix: ''
60local name: 'error', prefix: ''
61local name: 'include', prefix: ''
62-- getElementsByTagNameNS('*', '*') --
63local name: 'chapter', prefix: ''
64local name: 'title', prefix: ''
65local name: 'para', prefix: ''
66local name: 'include', prefix: 'xi'
67local name: 'fallback', prefix: 'xi'
68local name: 'error', prefix: ''
69local name: 'include', prefix: ''
70-- getElementsByTagNameNS('', '*') --
71local name: 'chapter', prefix: ''
72local name: 'title', prefix: ''
73local name: 'para', prefix: ''
74local name: 'error', prefix: ''
75local name: 'include', prefix: ''
76-- getElementsByTagNameNS('http://www.w3.org/2001/XInclude', '*') --
77local name: 'include', prefix: 'xi'
78local name: 'fallback', prefix: 'xi'
79-- getElementsByTagNameNS('', 'fallback') --
80-- getElementsByTagNameNS(null, 'fallback') --
81-- getElementsByTagNameNS(null, 'include') --
82local name: 'include', prefix: ''
83