2003-11-04 06:49:24 +08:00
|
|
|
--TEST--
|
2005-11-29 10:51:07 +08:00
|
|
|
SimpleXML: XPath
|
2003-11-04 06:49:24 +08:00
|
|
|
--SKIPIF--
|
|
|
|
<?php if (!extension_loaded("simplexml")) print "skip"; ?>
|
|
|
|
--FILE--
|
|
|
|
<?php
|
2004-01-18 23:14:03 +08:00
|
|
|
|
|
|
|
$xml =<<<EOF
|
|
|
|
<?xml version='1.0'?>
|
|
|
|
<!DOCTYPE sxe SYSTEM "notfound.dtd">
|
|
|
|
<sxe id="elem1">
|
|
|
|
<elem1 attr1='first'>
|
|
|
|
<!-- comment -->
|
|
|
|
<elem2>
|
|
|
|
<elem3>
|
|
|
|
<elem4>
|
|
|
|
<?test processing instruction ?>
|
|
|
|
</elem4>
|
|
|
|
</elem3>
|
|
|
|
</elem2>
|
|
|
|
</elem1>
|
|
|
|
</sxe>
|
|
|
|
EOF;
|
|
|
|
|
|
|
|
$sxe = simplexml_load_string($xml);
|
|
|
|
|
2004-01-18 03:41:32 +08:00
|
|
|
var_dump($sxe->xpath("elem1/elem2/elem3/elem4"));
|
2011-08-31 19:44:22 +08:00
|
|
|
//valid expression
|
2004-01-18 03:41:32 +08:00
|
|
|
var_dump($sxe->xpath("***"));
|
2011-08-31 19:44:22 +08:00
|
|
|
//invalid expression
|
|
|
|
var_dump($sxe->xpath("**"));
|
2003-11-04 06:49:24 +08:00
|
|
|
?>
|
|
|
|
--EXPECTF--
|
|
|
|
array(1) {
|
|
|
|
[0]=>
|
2004-03-30 03:58:01 +08:00
|
|
|
object(SimpleXMLElement)#%d (1) {
|
2003-11-04 06:49:24 +08:00
|
|
|
["test"]=>
|
2004-03-30 03:58:01 +08:00
|
|
|
object(SimpleXMLElement)#%d (0) {
|
2003-11-04 06:49:24 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-08-31 19:44:22 +08:00
|
|
|
array(0) {
|
|
|
|
}
|
|
|
|
|
|
|
|
Warning: SimpleXMLElement::xpath(): Invalid expression in %s on line %d
|
|
|
|
|
|
|
|
Warning: SimpleXMLElement::xpath(): xmlXPathEval: evaluation failed in %s on line %d
|
2003-11-04 06:49:24 +08:00
|
|
|
bool(false)
|