如何xpath查询xs:documentation的内部文本?
$xsd = simplexml_load_file('my_xsd_file.xsd');
// I have tried:
$xsd->xpath("./xs:complexType[1]/xs:annotation/xs:documentation");
$xsd->xpath("./xs:complexType[1]/xs:annotation/xs:documentation/text()");
$xsd->xpath("./xs:complexType[1]/xs:annotation/xs:documentation[text()]");
以上所有都返回一个空对象。
更新
打印此来电$xsd->getDocNamespaces();
会返回:
Array
(
[ds] => http://www.w3.org/2000/09/xmldsig#
[xs] => http://www.w3.org/2001/XMLSchema
[] => http://www.portalfiscal.inf.br/nfe
)
所以在我看来,命名空间已正确注册。
答案 0 :(得分:1)
您还必须使用匹配的名称空间URI注册名称空间前缀xs
。
$xsd->registerXPathNamespace('xs', 'http://www.w3.org/2001/XMLSchema');
此外,您省略了根元素<xs:schema/>
的第一个轴步骤。
$xsd->xpath("/xs:schema/xs:complexType[1]/xs:annotation/xs:documentation");
答案 1 :(得分:0)
显然PHP 5.4 xpath https://bugs.php.net/bug.php?id=62203
上存在错误我在PHP 5.3上测试了我的代码,它运行得很好。