GNOME Bugzilla – Bug 750037
XPath searching for nodes within a namespace only finds every second node
Last modified: 2016-05-05 14:11:03 UTC
The running the following XPath over the example XML should find all element nodes since all of their ancestor-or-self contains a matching namespace declaration. However, it only finds every second node, i.e. <root/>, <two/> and <four/>. XML: <root xmlns:ns="foo"ns:id="1"> <one/> <two/> <three/> <four/> <five/> </root> XPath: //node()[namespace::ns]
Weird indeed, I can reproduce it, sounds like a genuine bug :-\ thinkpad2:~/XML -> ./xmllint --shell tst750037.xml / > setns ns=foo / > xpath //node() Object is a Node Set : Set contains 12 nodes: 1 ELEMENT root namespace ns href=foo ATTRIBUTE id TEXT content=1 2 TEXT content= 3 ELEMENT one 4 TEXT content= 5 ELEMENT two 6 TEXT content= 7 ELEMENT three 8 TEXT content= 9 ELEMENT four 10 TEXT content= 11 ELEMENT five 12 TEXT content= / > xpath //node()[namespace::ns] Object is a Node Set : Set contains 3 nodes: 1 ELEMENT root namespace ns href=foo ATTRIBUTE id TEXT content=1 2 ELEMENT two 3 ELEMENT four / > quit
Fixed with the following commit: https://git.gnome.org/browse/libxml2/commit/?id=82b73039dc0eed620621cb699b1140c6e0c89cce