XPath and namespace specification for XML documents with an explicit default namespace

后端 未结 3 796
深忆病人
深忆病人 2020-12-03 19:25

I\'m struggling to get the correct combination of an XPath expression and the namespace specification as required by package XML (argument namespaces) f

3条回答
  •  执念已碎
    2020-12-03 20:09

    Namespace definition without prefix (xmlns="...") is default namespace. In case of XML document having default namespace, the element where default namespace declared and all of it's descendant without prefix and without different default namespace declaration are considered in that aforementioned default namespace.

    Therefore, in your case you need to use prefix registered for default namespace at the beginning of all elements in the XPath, for example :

    /xmlns:doc//xmlns:b[@omegahat:status='foo']
    

    UPDATE :

    Actually I'm not a user of r, but looking at some references on net something like this may work :

    getNodeSet(doc, "/ns:doc//ns:b[@omegahat:status='foo']", c(ns="http://something.org"))
    

提交回复
热议问题