PHP registerXPathNamespace()函数讲解
时间:2020-10-12 19:22:44|栏目:PHP代码|点击: 次
PHP registerXPathNamespace() 函数
实例
为下一个 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>";
}
?>
定义和用法
registerXPathNamespace()函数为下一个 XPath 查询创建命名空间上下文。
如果在 XML 文档中改变命名空间前缀,这个函数很有用。registerXPathNamespace()函数将创建一个指定的命名空间前缀,使受影响的 XML 节点可以在不改变应用程序代码太多的情况下进行访问。
语法
registerXPathNamespace( _prefix_ , _ns_ );


总结
栏 目:PHP代码
下一篇:PHP加密3DES报错 Call to undefined function: mcrypt_module_open() 如何解决
本文标题:PHP registerXPathNamespace()函数讲解
本文地址:http://www.codeinn.net/misctech/10375.html






