I'm thinking it should look something like this, assuming Python language: Import xmlsec Import libxml2
...
def test_get_xml_fragment(self,xpath,ns): ret = None context = self.doc.xpathNewContext() if ns is None:
context.xpathRegisterNs(ns,'http://127.0.0.1/#no_place_like_home') res = context.xpathEval(xpath) i = 0 for node in res: print i,':',node i = i + 1
Please note there is an object in the mix, and I can get the whole to work great without namespaces. One good example of how Python should be handling namespaces in this case would be great. Even telling me it's forever broken...this too would be good to know. (Also, this is not an ideal example...I get this. I want something that hobbles before I get something hat soars.)
Thanks in advance.
Sent from my Planet Message: 2Date: Fri, 30 Jan 2015 09:03:40 -0600From: Ross Reedstrom <reedstrm rice edu>To: xml gnome orgSubject: Re: [xml] Xpath issues with libxml2Message-ID: <20150130150340 GA28262 rice edu>Content-Type: text/plain; charset=us-asciiAlex -With out examples of what you've tried, it's hard to diagnose the problem.However, seeing 'namespaces' and 'never returns anything' makes me think you'rehaving issues with the default namespace concept. While XML documents have adefault namespace, XPaths do not. Once you use namespaces in an xml document,all your xpaths will need to use namespace declarations for all the path parts,even for tags that are defaulted in the document. So, you'll need to declarea namespace prefix that matches the default namespace in the doc. Give usa small example that you've tried that doesn't work, we'll fix it.RossOn Fri, Jan 30, 2015 at 08:44:15AM -0500, Alex Boese wrote:Forgive me if this is a deprecated approach (as I am not fully aware), but I was utilizing "default" libxml2 bindings (not lxml) in Python to retrieve xml fragments via xpath functions. Normally this seems to work fine, but with namespace declarations this seems especially problematic as nothing ever returns and nothing errors. Would it be possible to confirm what correct functions and order of operations would be for this? Even if the example is C, I can translate that to Python.
-- Ross Reedstrom, Ph.D. reedstrm rice eduSystems Engineer & Admin, Research Scientist phone: 713-348-6166Connexions http://cnx.org fax: 713-348-3665Rice University MS-375, Houston, TX 77005GPG Key fingerprint = F023 82C8 9B0E 2CC6 0D8E F888 D3AE 810E 88F0 BEDE------------------------------Subject: Digest Footer_______________________________________________xml mailing listxml gnome orghttps://mail.gnome.org/mailman/listinfo/xml------------------------------End of xml Digest, Vol 128, Issue 2***********************************
|