title: Python lxml: how to fetch XML tag names with xpath selector?
body: <p>I'm trying to parse the following XML using Python and <code>lxml</code>:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;?xml-stylesheet type="text/xsl" href="/bind9.xsl"?&gt;
  &lt;isc version="1.0"&gt;
    &lt;bind&gt;
      &lt;statistics version="2.2"&gt;
        &lt;memory&gt;
          &lt;summary&gt;
            &lt;TotalUse&gt;1232952256
            &lt;/TotalUse&gt;
            &lt;InUse&gt;835252452
            &lt;/InUse&gt;
            &lt;BlockSize&gt;598212608
            &lt;/BlockSize&gt;
            &lt;ContextSize&gt;52670016
            &lt;/ContextSize&gt;
            &lt;Lost&gt;0
            &lt;/Lost&gt;
          &lt;/summary&gt;
        &lt;/memory&gt;
      &lt;/statistics&gt;
    &lt;/bind&gt;
  &lt;/isc&gt;
  </code></pre>
  
  <p>The goal is to extract the tag name and text of every element under <code>bind/statistics/memory/summary</code> in order to produce the following mapping:</p>
  
  <pre><code>TotalUse: 1232952256
  InUse: 835252452
  BlockSize: 598212608
  ContextSize: 52670016
  Lost: 0
  </code></pre>
  
  <p>I've managed to extract the element values, but I can't figure out the xpath expression to get the element tag names.</p>
  
  <p>A sample script:</p>
  
  <pre><code>from lxml import etree as et
  
  def main():
  
      xmlfile = "bind982.xml"
      location = "bind/statistics/memory/summary/*"
      label_selector = "??????" ## what to put here...?
      value_selector = "text()"
  
      with open(xmlfile, "r") as data:
          xmldata = et.parse(data)
  
          etree = xmldata.getroot()
  
          statlist = etree.xpath(location)
  
          for stat in statlist:
              label = stat.xpath(label_selector)[0]
              value = stat.xpath(value_selector)[0]
              print "{0}: {1}".format(label, value)
  
  if __name__ == '__main__':
      main()
  </code></pre>
  
  <p>I know I could use <code>value = stat.tag</code> instead of <code>stat.xpath()</code>, but the script must be sufficiently generic to also process other pieces of XML where the label selector is different.</p>
  
  <p>What xpath selector would return an element's tag name?</p>