1--TEST-- 2Test Dom\XPath::query() with registering a context node's in-scope namespaces 3--EXTENSIONS-- 4dom 5--FILE-- 6<?php 7 8function dump($xpath, $query, $context) { 9 echo "--- $query ---\n"; 10 $nodes = $xpath->query($query, $context); 11 foreach ($nodes as $node) { 12 echo "nodeName: "; 13 var_dump($node->nodeName); 14 echo "prefix: "; 15 var_dump($node->prefix); 16 echo "namespaceURI: "; 17 var_dump($node->namespaceURI); 18 } 19 if (count($nodes) === 0) { 20 echo "No nodes found\n"; 21 } 22} 23 24$dom = Dom\XMLDocument::createFromString(<<<XML 25<a xmlns="urn:a" xmlns:d="urn:d"> 26 <b:b xmlns:b="urn:b"> 27 <c:c1 xmlns:c="urn:c1"> 28 <b:bar/> 29 <c:c2 xmlns:c="urn:c2"/> 30 <c:c3 xmlns:c="urn:c3"/> 31 <c:c4 xmlns:c="urn:c1"/> 32 <d:d/> 33 <a/> 34 </c:c1> 35 </b:b> 36</a> 37XML); 38 39$c1 = $dom->getElementsByTagNameNS('*', 'c1')->item(0); 40$c2 = $dom->getElementsByTagNameNS('*', 'c1')->item(0); 41 42$xpath = new Dom\XPath($dom); 43 44echo "=== Tests with c1 ===\n\n"; 45 46dump($xpath, '//b:bar', $c1); 47dump($xpath, '//c:c1', $c1); 48dump($xpath, '//c:c2', $c1); 49dump($xpath, '//c:c3', $c1); 50dump($xpath, '//c:c4', $c1); 51dump($xpath, '//d:d', $c1); 52dump($xpath, '//a', $c1); 53 54echo "\n=== Tests with c2 ===\n\n"; 55 56dump($xpath, '//c:c1', $c2); 57dump($xpath, '//c:c2', $c2); 58dump($xpath, '//d:d', $c2); 59 60?> 61--EXPECT-- 62=== Tests with c1 === 63 64--- //b:bar --- 65nodeName: string(5) "b:bar" 66prefix: string(1) "b" 67namespaceURI: string(5) "urn:b" 68--- //c:c1 --- 69nodeName: string(4) "c:c1" 70prefix: string(1) "c" 71namespaceURI: string(6) "urn:c1" 72--- //c:c2 --- 73No nodes found 74--- //c:c3 --- 75No nodes found 76--- //c:c4 --- 77nodeName: string(4) "c:c4" 78prefix: string(1) "c" 79namespaceURI: string(6) "urn:c1" 80--- //d:d --- 81nodeName: string(3) "d:d" 82prefix: string(1) "d" 83namespaceURI: string(5) "urn:d" 84--- //a --- 85No nodes found 86 87=== Tests with c2 === 88 89--- //c:c1 --- 90nodeName: string(4) "c:c1" 91prefix: string(1) "c" 92namespaceURI: string(6) "urn:c1" 93--- //c:c2 --- 94No nodes found 95--- //d:d --- 96nodeName: string(3) "d:d" 97prefix: string(1) "d" 98namespaceURI: string(5) "urn:d" 99