Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><a href="http://lxml.de/" rel="nofollow">lxml</a> uses libxml2 and provides a nicer interface (<a href="http://docs.python.org/library/xml.etree.elementtree.html" rel="nofollow">the ElementTree api</a>) so you get most of the benefit of libxml2's speed and all of the benefit of it's xpath evaluation.</p> <pre><code>import lxml.etree as ET doc = ET.parse(file) owner = doc.find('/*/Class[@name="'+className+'" and @version="'+classVersion+'"]/Owner') if owner: print owner.get('user-login') </code></pre> <p>The added bonus is that the Element Tree api is available by default in python2.5 (though the version in 1.5 does not include the <code>[@name='value']</code> xpath syntax, that was added in python 2.7, but you can get the <a href="http://effbot.org/zone/elementtree-13-intro.htm" rel="nofollow">1.3 api as a separate package</a> in older 2.x versions of python).</p> <p>You can import any compatible version of the ElementTree api using:</p> <pre><code>try: from lxml import etree print("running with lxml.etree") except ImportError: try: # Python 2.5 import xml.etree.cElementTree as etree print("running with cElementTree on Python 2.5+") except ImportError: try: # Python 2.5 import xml.etree.ElementTree as etree print("running with ElementTree on Python 2.5+") except ImportError: try: # normal cElementTree install import cElementTree as etree print("running with cElementTree") except ImportError: try: # normal ElementTree install import elementtree.ElementTree as etree print("running with ElementTree") except ImportError: print("Failed to import ElementTree from any known place") </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload