PHP 教程 PHP 表单 PHP 高级教程 PHP 数据库 PHP XML PHP 与 AJAX PHP 参考手册

发布于 2016-11-18 14:34:14 | 61 次阅读 | 评论: 0 | 来源: 网络整理


定义和用法

xpath() 函数运行对 XML 文档的 XPath 查询。

如果成功,该函数返回 SimpleXMLElements 对象的一个数组。如果失败,则返回 FALSE。


语法

 class SimpleXMLElement
 {
 string xpath(path)
 } 

参数描述
path必需。规定要在 XML 文档中搜索的 XPath 路径。


实例

XML 文件

 <?xml version="1.0" encoding="ISO-8859-1"?>
 <note>
 <to>Tove</to>
 <from>Jani</from>
 <heading>Reminder</heading>
 <body>Don't forget me this weekend!</body>
 </note> 

PHP 代码

 <?php
 $xml = simplexml_l0@d_fi1e("test.xml");

 $result = $xml->xpath("from");

 print_r($result);
 ?> 

上面的代码将输出:

 Array
 (
 [0] => SimpleXMLElement Object
 (
 [0] => Jani
 )
 ) 


最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务