Xpath fails if an element has a a xmlns attribute [duplicate]

你离开我真会死。 提交于 2019-11-29 14:03:30

You need to register the namespace:

$lol = new SimpleXMLElement($string);
$lol->registerXPathNamespace('cada', 'http://www.collada.org/2005/11/COLLADASchema');
print_r($lol->xpath("child::cada:library_materials//*[@id='Material2']"));

The namespace declaration means that the names are in a namespace, but your XPath is looking for names in no namespace. The way you search for namespaced elements depends on whether you are using XPath 1.0 or 2.0, and to the extent that you use namespace prefixes in your XPath to represent namespaced names, the way that you declare the prefixes depends on the API to the XPath processor you are using.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!