xml - How can I write a namespace agnostic XPath query using XPath axes -
let's have xml presented below:
<ns1:test xmlns:ns1="http://www.w3.org/tr/html3/" xmlns:uml="http://www.w3.org/tr/html4/"> <uml:class name="test1"> <uml:modelelement.stereotype> <uml:stereotype name="afv"/> </uml:modelelement.stereotype> </uml:class> <uml:class name="test2" > <uml:modelelement.stereotype> <uml:stereotype name="afv"/> </uml:modelelement.stereotype> </uml:class> <uml:class name="test3" > <uml:modelelement.stereotype> <uml:stereotype name="rcs"/> </uml:modelelement.stereotype> </uml:class> <uml:class name="test4" > <uml:modelelement.stereotype> <uml:stereotype name="dfk"/> </uml:modelelement.stereotype> </uml:class> <uml:class name="test5" > <uml:modelelement.stereotype> <uml:stereotype name="dso"/> </uml:modelelement.stereotype> </uml:class> </ns1:test>
how can write namespace agnostic xpath query "class" elements containing "stereotype" element attribute name equal "afv" ?
if there weren't namespaces, have use called xpath axes, , query have looked : //class[descendant::stereotype[@name='afv']]
the xpath query should return:
<uml:class name="test1"> <uml:modelelement.stereotype> <uml:stereotype name="afv"/> </uml:modelelement.stereotype> </uml:class> <uml:class name="test2" > <uml:modelelement.stereotype> <uml:stereotype name="afv"/> </uml:modelelement.stereotype> </uml:class>
you can use xpath local-name()
function match element's local name ignoring namespaces :
//*[local-name()='class'][descendant::*[local-name()='stereotype' , @name='afv']]
Comments
Post a Comment