PHP registerXPathNamespace()函數(shù)講解
PHP registerXPathNamespace() 函數(shù)
實例
為下一個 XPath 查詢創(chuàng)建命名空間上下文:
<?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()
函數(shù)為下一個 XPath 查詢創(chuàng)建命名空間上下文。
如果在 XML 文檔中改變命名空間前綴,這個函數(shù)很有用。registerXPathNamespace()函數(shù)將創(chuàng)建一個指定的命名空間前綴,使受影響的 XML 節(jié)點可以在不改變應(yīng)用程序代碼太多的情況下進(jìn)行訪問。
語法
registerXPathNamespace( _prefix_ , _ns_ );
總結(jié)
以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,謝謝大家對腳本之家的支持。如果你想了解更多相關(guān)內(nèi)容請查看下面相關(guān)鏈接
相關(guān)文章
分享下PHP register_globals 值為on與off的理解
從 PHP4.2.0版本開始,php.ini中的設(shè)置選項 register_globals 默認(rèn)值變成了 off。所以,最好從現(xiàn)在就開始用Off的風(fēng)格開始編程2013-09-09