参数 | 描述 |
---|---|
prefix | 必需。规定命名空间前缀。 |
ns | 必需。规定命名空间 URL。必须匹配 XML 文档中的命名空间。 |
XML 文件:
<?xml version="1.0" encoding="ISO-8859-1"?> <note xmlns:b="http://www.w3school.com.cn/example/"> <to>George</to> <from>John</from> <heading>Reminder</heading> <b:body>Dont forget the meeting!</b:body> </note>
PHP 代码:
<?php
$xml = simplexml_load_file("test.xml");
$xml->registerXPathNamespace("msg", "http://www.w3school.com.cn/example/");
$result = $xml->xpath("msg:body");
foreach ($result as $message)
{
echo $message;
}
?>
输出类似:
Dont forget the meeting!