我试图从这个文件http://www.uniprot.org/uniprot/P12345.xml中获取节点的值“/entry/评论型=”亚细胞位置“/subcellularLocation/location”
我使用的是SimpleXML和xpath,但是我无法使用以下方法访问这个节点:
$var = "http://www.uniprot.org/uniprot/P12345.xml";
$Unip_result= new SimpleXMLElement($var, NULL, TRUE);
$value=$Unip_result->xpath("/entry/comment[@type='subcellular location']");结果是一个空数组..。
发布于 2014-09-24 12:06:20
您的XML有默认名称空间(没有前缀的名称空间:xmlns="....")。在祖先的默认名称空间中考虑声明默认命名空间的元素及其所有不带前缀和没有不同默认命名空间的后代。因此,您需要注册一个指向默认命名空间URI的前缀,并在XPath中使用该前缀:
$var = "http://www.uniprot.org/uniprot/P12345.xml";
$Unip_result = new SimpleXMLElement($var, NULL, TRUE);
$Unip_result->registerXPathNamespace('ns', 'http://uniprot.org/uniprot');
$value = $Unip_result->xpath("/ns:uniprot/ns:entry/ns:comment[@type='subcellular location']");发布于 2014-09-23 17:50:11
XML有名称空间,您需要为它注册一个前缀,并在XPath表达式中使用前缀。检查SimpleXMLElement::registerXpathNamespace()。
https://stackoverflow.com/questions/25998706
复制相似问题