PHP registerXPathNamespace() 函数
PHP 教程
· 2019-01-29 08:13:34
实例
为下一个 XPath 查询创建命名空间上下文:
<?php
$xml=<<<XML
<book xmlns:chap="http://example.org/chapter-title">
<title>My Book</title>
<chapter id="1">
<chap:title>Chapter 1</chap:title>
<para>Donec velit. Nullam eget tellus...</para>
</chapter>
<chapter id="2">
<chap:title>Chapter 2</chap:title>
<para>Lorem ipsum dolor sit amet....</para>
</chapter>
</book>
XML;
$sxe=new SimpleXMLElement($xml);
$sxe->registerXPathNamespace('c','http://example.org/chapter-title');
$result=$sxe->xpath('//c:title');
foreach ($result as $title)
{
echo $title . "<br>";
}
?>
$xml=<<<XML
<book xmlns:chap="http://example.org/chapter-title">
<title>My Book</title>
<chapter id="1">
<chap:title>Chapter 1</chap:title>
<para>Donec velit. Nullam eget tellus...</para>
</chapter>
<chapter id="2">
<chap:title>Chapter 2</chap:title>
<para>Lorem ipsum dolor sit amet....</para>
</chapter>
</book>
XML;
$sxe=new SimpleXMLElement($xml);
$sxe->registerXPathNamespace('c','http://example.org/chapter-title');
$result=$sxe->xpath('//c:title');
foreach ($result as $title)
{
echo $title . "<br>";
}
?>
定义和用法
registerXPathNamespace() 函数为下一个 XPath 查询创建命名空间上下文。
如果在 XML 文档中改变命名空间前缀,这个函数很有用。registerXPathNamespace()函数将创建一个指定的命名空间前缀,使受影响的 XML 节点可以在不改变应用程序代码太多的情况下进行访问。
语法
registerXPathNamespace(prefix,ns);
参数 | 描述 |
---|---|
prefix | 必需。规定在 ns 指定的命名空间的 XPath 查询中使用的的命名空间前缀。 |
ns | 必需。规定用于 XPath 查询的命名空间。 |
技术细节
返回值: | 如果成功则返回 TRUE,如果失败则返回 FALSE。 |
---|---|
PHP 版本: | 5.2+ |
点击查看所有 PHP 教程 文章: https://www.codercto.com/courses/l/5.html
图论算法理论、实现及应用
王桂平//王衍//任嘉辰 / 北京大学 / 2011-1 / 54.00元
《图论算法理论、实现及应用》系统地介绍了图论算法理论,并选取经典的ACM/ICPC竞赛题目为例题阐述图论算法思想,侧重于图论算法的程序实现及应用。《图论算法理论、实现及应用》第1章介绍图的基本概念和图的两种存储表示方法:邻接矩阵和邻接表,第2~9章分别讨论图的遍历与活动网络问题,树与图的生成树,最短路径问题,可行遍性问题,网络流问题,支配集、覆盖集、独立集与匹配,图的连通性问题,平面图及图的着色问......一起来看看 《图论算法理论、实现及应用》 这本书的介绍吧!