xref: /PHP-5.6/ext/simplexml/tests/008.phpt (revision e1813b69)
1--TEST--
2SimpleXML: XPath
3--SKIPIF--
4<?php if (!extension_loaded("simplexml")) print "skip"; ?>
5--FILE--
6<?php
7
8$xml =<<<EOF
9<?xml version='1.0'?>
10<!DOCTYPE sxe SYSTEM "notfound.dtd">
11<sxe id="elem1">
12 <elem1 attr1='first'>
13  <!-- comment -->
14  <elem2>
15   <elem3>
16    <elem4>
17     <?test processing instruction ?>
18    </elem4>
19   </elem3>
20  </elem2>
21 </elem1>
22</sxe>
23EOF;
24
25$sxe = simplexml_load_string($xml);
26
27var_dump($sxe->xpath("elem1/elem2/elem3/elem4"));
28//valid expression
29var_dump($sxe->xpath("***"));
30//invalid expression
31var_dump($sxe->xpath("**"));
32?>
33--EXPECTF--
34array(1) {
35  [0]=>
36  object(SimpleXMLElement)#%d (1) {
37    ["test"]=>
38    object(SimpleXMLElement)#%d (0) {
39    }
40  }
41}
42array(0) {
43}
44
45Warning: SimpleXMLElement::xpath(): Invalid expression in %s on line %d
46
47Warning: SimpleXMLElement::xpath(): xmlXPathEval: evaluation failed in %s on line %d
48bool(false)
49