After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 322890 - xpath doesn't work correctly when there are schemas specified in xml file
xpath doesn't work correctly when there are schemas specified in xml file
Status: RESOLVED INVALID
Product: libxml2
Classification: Platform
Component: general
2.6.22
Other Linux
: Normal normal
: ---
Assigned To: Daniel Veillard
libxml QA maintainers
Depends on:
Blocks:
 
 
Reported: 2005-11-30 23:14 UTC by Arkadiusz Miskiewicz
Modified: 2005-12-01 08:30 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Arkadiusz Miskiewicz 2005-11-30 23:14:42 UTC
Distribution/Version: PLD Ac

test1.xml contains schema specs; test2.xml doesn't.
a.py does the same thing on test1.xml as b.py on test2.xml.
xpath in a.py doesn't find anything while in b.py does.

$ cat test1.xml
<?xml version="1.0" encoding="UTF-8"?>
<epp xmlns="http://www.eurid.eu/xml/epp/epp-1.0"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:contact="http://www.eurid.eu/xml/epp/contact-1.0"
        xmlns:domain="http://www.eurid.eu/xml/epp/domain-1.0"
        xmlns:eurid="http://www.eurid.eu/xml/epp/eurid-1.0"
        xmlns:nsgroup="http://www.eurid.eu/xml/epp/nsgroup-1.0"
        xsi:schemaLocation="http://www.eurid.eu/xml/epp/epp-1.0 epp-1.0.xsd
        http://www.eurid.eu/xml/epp/contact-1.0 contact-1.0.xsd
        http://www.eurid.eu/xml/epp/domain-1.0 domain-1.0.xsd
        http://www.eurid.eu/xml/epp/eurid-1.0 eurid-1.0.xsd
        http://www.eurid.eu/xml/epp/nsgroup-1.0 nsgroup-1.0.xsd">
        <response>
                <result code="1000">
                        <msg>Command completed successfully</msg>
                </result>
                <trID>
                        <clTRID>TRID-0001</clTRID>
                        <svTRID>eurid-3650743</svTRID>
                </trID>
        </response>
</epp>

$ cat a.py
#!/usr/bin/python -u
import libxml2
doc = libxml2.parseFile("test1.xml")
ctxt = doc.xpathNewContext()
res = ctxt.xpathEval("//result/msg")
print res;
libxml2.cleanupParser()
$ python a.py
[]
$ cat test2.xml
<?xml version="1.0" encoding="UTF-8"?>
<epp>
        <response>
                <result code="1000">
                        <msg>Command completed successfully</msg>
                </result>
                <trID>
                        <clTRID>TRID-0001</clTRID>
                        <svTRID>eurid-3650743</svTRID>
                </trID>
        </response>
</epp>

$ cat b.py
#!/usr/bin/python -u
import libxml2
doc = libxml2.parseFile("test2.xml")
ctxt = doc.xpathNewContext()
res = ctxt.xpathEval("//result/msg")
print res;
libxml2.cleanupParser()
$ python b.py
[<xmlNode (msg) object at 0x302e8288>]
$
Comment 1 jor 2005-11-30 23:48:45 UTC
Unfortunatly, you just left the IRC channel before I could answer your question.
But this is not a bug. 'Standalone' Xpath (e.g. not inside xslt), doesn't know
anything about the default namespace. Any node name without a prefix is
considered to be in the 'null' namespace (see
http://www.w3.org/TR/xpath#node-sets). So b.py works because there's no
namespace in the source xml. In a.py, you can either use local-name() or else
you need to specify a namespace for the default one, for example add before the
xpathEval:
root = doc.getRootElement()
defaultNS = root.searchNs(root,None).content
ctxt.xpathRegisterNs('default',defaultNS)
res = ctxt.xpathEval("//default:result/default:msg")
Comment 2 Arkadiusz Miskiewicz 2005-12-01 08:30:03 UTC
Thanks, after registering some default namespace it works nicely! Sorry for a 
noise.