1--TEST-- 2Dom\XMLDocument interaction with XPath 3--EXTENSIONS-- 4dom 5--FILE-- 6<?php 7 8$dom = Dom\XMLDocument::createFromString(<<<XML 9<?xml version="1.0"?> 10<root> 11 <p>hi</p> 12 <element xmlns="urn:e" xmlns:a="urn:a"> 13 <?target data?> 14 <!-- comment --> 15 </element> 16</root> 17XML); 18 19$xpath = new Dom\XPath($dom); 20 21echo "--- Get data of the paragraph ---\n"; 22 23$result = $xpath->query("//p"); 24var_dump($result); 25var_dump($result->item(0)->textContent); 26 27$result = $xpath->evaluate("//p"); 28var_dump($result); 29var_dump($result->item(0)->textContent); 30 31var_dump($xpath->evaluate("string(//p)")); 32var_dump($xpath->evaluate("string-length(//p)")); 33var_dump($xpath->evaluate("boolean(//p)")); 34 35echo "--- Get data of special nodes ---\n"; 36 37$result = $xpath->query("//*/comment()|//*/processing-instruction()"); 38foreach ($result as $item) { 39 var_dump(get_class($item)); 40 var_dump($item->textContent); 41} 42 43echo "--- Get a namespace node ---\n"; 44 45// Namespace nodes don't exist in modern day DOM. 46try { 47 var_dump($xpath->evaluate("//*/namespace::*")); 48} catch (DOMException $e) { 49 echo $e->getCode(), ": ", $e->getMessage(), "\n"; 50} 51 52?> 53--EXPECT-- 54--- Get data of the paragraph --- 55object(Dom\NodeList)#4 (1) { 56 ["length"]=> 57 int(1) 58} 59string(2) "hi" 60object(Dom\NodeList)#5 (1) { 61 ["length"]=> 62 int(1) 63} 64string(2) "hi" 65string(2) "hi" 66float(2) 67bool(true) 68--- Get data of special nodes --- 69string(25) "Dom\ProcessingInstruction" 70string(4) "data" 71string(11) "Dom\Comment" 72string(9) " comment " 73--- Get a namespace node --- 749: The namespace axis is not well-defined in the living DOM specification. Use Dom\Element::getInScopeNamespaces() or Dom\Element::getDescendantNamespaces() instead. 75