xpath() 函数运行对 XML 文档的 XPath 查询。
如果成功,则返回包含 SimpleXMLElement 对象的一个数组。如果失败,则返回 false。
</>code
- class SimpleXMLElement
- {
- string xpath(path)
- }
参数 | 描述 |
---|---|
path | 必需。XPath 路径。 |
XML 文件:
</>code
- <?xml version="1.0" encoding="ISO-8859-1"?>
- <note>
- <to>George</to>
- <from>John</from>
- <heading>Reminder</heading>
- <body>Don't forget the meeting!</body>
- </note>
PHP 代码:
</>code
- <?php
- $xml = simplexml_load_file("test.xml");
- $result =
$xml->xpath("from")
;- print_r($result);
- ?>
输出:
</>code
- Array
- (
- [0] => SimpleXMLElement Object
- (
- [0] => John
- )
- )
如对本文有疑问,请提交到交流论坛,广大热心网友会为你解答!! 点击进入论坛
Powered by 365建站网 RSS地图 HTML地图
copyright © 2013-2024 版权所有 鄂ICP备17013400号