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_ );
总结
Copyright © 2019- how1234.cn 版权所有
违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com
本站由北京市万商天勤律师事务所王兴未律师提供法律服务