mirror of
https://github.com/php/php-src.git
synced 2026-03-24 00:02:20 +01:00
Add XPath test with a context node
This commit is contained in:
31
ext/dom/tests/xpath_context_node.phpt
Normal file
31
ext/dom/tests/xpath_context_node.phpt
Normal file
@@ -0,0 +1,31 @@
|
||||
--TEST--
|
||||
XPath: with a context node
|
||||
--EXTENSIONS--
|
||||
dom
|
||||
--FILE--
|
||||
<?php
|
||||
$dom = new DOMDocument();
|
||||
$dom->loadXML(<<<XML
|
||||
<root>
|
||||
<child>
|
||||
<p>bar</p>
|
||||
</child>
|
||||
<child>
|
||||
<p>foo1</p>
|
||||
<p>foo2</p>
|
||||
</child>
|
||||
</root>
|
||||
XML);
|
||||
$xpath = new DOMXpath($dom);
|
||||
|
||||
foreach ($xpath->query("p", $dom->documentElement->firstElementChild->nextElementSibling) as $p) {
|
||||
echo $p->textContent, "\n";
|
||||
}
|
||||
|
||||
var_dump($xpath->evaluate("count(p)", $dom->documentElement->firstElementChild->nextElementSibling));
|
||||
|
||||
?>
|
||||
--EXPECT--
|
||||
foo1
|
||||
foo2
|
||||
float(2)
|
||||
Reference in New Issue
Block a user