<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div>I'm thinking it should look something like this, assuming Python language:<br><br><span style="background-color: rgba(255, 255, 255, 0);">Import xmlsec<br>Import libxml2<br><br>...<br><br>    def test_get_xml_fragment(self,xpath,ns):<br>         ret = None<br>         context = self.doc.xpathNewContext()<br>         if ns is None:<br><br>context.xpathRegisterNs(ns,'<a href="http://127.0.0.1/#no_place_like_home'" x-apple-data-detectors="true" x-apple-data-detectors-type="link" x-apple-data-detectors-result="0">http://127.0.0.1/#no_place_like_home'</a>)<br>         res = context.xpathEval(xpath)<br>         i = 0<br>         for node in res:<br>              print i,':',node<br>              i = i + 1</span></div><div><br></div><div><br>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.)</div><div><br></div><div>Thanks in advance.<br><br>Sent from my Planet</div><blockquote type="cite"><div><span></span><span></span><br><span>Message: 2</span><br><span>Date: Fri, 30 Jan 2015 09:03:40 -0600</span><br><span>From: Ross Reedstrom <<a href="mailto:reedstrm@rice.edu">reedstrm@rice.edu</a>></span><br><span>To: <a href="mailto:xml@gnome.org">xml@gnome.org</a></span><br><span>Subject: Re: [xml] Xpath issues with libxml2</span><br><span>Message-ID: <<a href="mailto:20150130150340.GA28262@rice.edu">20150130150340.GA28262@rice.edu</a>></span><br><span>Content-Type: text/plain; charset=us-ascii</span><br><span></span><br><span>Alex -</span><br><span>With out examples of what you've tried, it's hard to diagnose the problem.</span><br><span>However, seeing 'namespaces' and 'never returns anything' makes me think you're</span><br><span>having issues with the default namespace concept. While XML documents have a</span><br><span>default namespace, XPaths do not. Once you use namespaces in an xml document,</span><br><span>all your xpaths will need to use namespace declarations for all the path parts,</span><br><span>even for tags that are defaulted in the document. So, you'll need to declare</span><br><span>a namespace prefix that matches the default namespace in the doc. Give us</span><br><span>a small example that you've tried that doesn't work, we'll fix it.</span><br><span></span><br><span>Ross</span><br><span></span><br><span>On Fri, Jan 30, 2015 at 08:44:15AM -0500, Alex Boese wrote:</span><br><blockquote type="cite"><span>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.</span><br></blockquote><blockquote type="cite"><span></span><br></blockquote><span></span><br><span>-- </span><br><span>Ross Reedstrom, Ph.D.                                 <a href="mailto:reedstrm@rice.edu">reedstrm@rice.edu</a></span><br><span>Systems Engineer & Admin, Research Scientist        phone: 713-348-6166</span><br><span>Connexions                  <a href="http://cnx.org">http://cnx.org</a>            fax: 713-348-3665</span><br><span>Rice University MS-375, Houston, TX 77005</span><br><span>GPG Key fingerprint = F023 82C8 9B0E 2CC6 0D8E  F888 D3AE 810E 88F0 BEDE</span><br><span></span><br><span></span><br><span>------------------------------</span><br><span></span><br><span>Subject: Digest Footer</span><br><span></span><br><span>_______________________________________________</span><br><span>xml mailing list</span><br><span><a href="mailto:xml@gnome.org">xml@gnome.org</a></span><br><span><a href="https://mail.gnome.org/mailman/listinfo/xml">https://mail.gnome.org/mailman/listinfo/xml</a></span><br><span></span><br><span></span><br><span>------------------------------</span><br><span></span><br><span>End of xml Digest, Vol 128, Issue 2</span><br><span>***********************************</span><br></div></blockquote></body></html>