registerXPathNamespace() 函数为下一次 XPath 查询创建命名空间语境。
</>code
- class SimpleXMLElement
- {
- string registerXPathNamespace(prefix,ns)
- }
参数 | 描述 |
---|---|
prefix | 必需。规定命名空间前缀。 |
ns | 必需。规定命名空间 URL。必须匹配 XML 文档中的命名空间。 |
XML 文件:
</>code
- <?xml version="1.0" encoding="ISO-8859-1"?>
- <note xmlns:b="https://www.365jz.com/example/">
- <to>George</to>
- <from>John</from>
- <heading>Reminder</heading>
- <b:body>Don't forget the meeting!</b:body>
- </note>
PHP 代码:
</>code
- <?php
- $xml = simplexml_load_file("test.xml");
$xml->registerXPathNamespace("msg", "https://www.365jz.com/example/");
- $result = $xml->xpath("msg:body");
- foreach ($result as $message)
- {
- echo $message;
- }
- ?>
输出类似:
</>code
- Don't forget the meeting!
如对本文有疑问,请提交到交流论坛,广大热心网友会为你解答!! 点击进入论坛
Powered by 365建站网 RSS地图 HTML地图
copyright © 2013-2024 版权所有 鄂ICP备17013400号