title: XPath with LXML Element
body: <p>I am trying to parse an XML document using lxml etree. The XML doc I am parsing looks like this:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;metadata xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.openarchives.org/OAI/2.0/"&gt;\t
      &lt;codeBook version="2.5" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="ddi:codebook:2_5" xsi:schemaLocation="ddi:codebook:2_5 http://www.ddialliance.org/Specification/DDI-Codebook/2.5/XMLSchema/codebook.xsd"&gt;
          &lt;docDscr&gt;
              &lt;citation&gt;
                  &lt;titlStmt&gt;
                      &lt;titl&gt;Test Title&lt;/titl&gt;
                  &lt;/titlStmt&gt;
                  &lt;prodStmt&gt;
                      &lt;prodDate/&gt;
                  &lt;/prodStmt&gt;
              &lt;/citation&gt;
          &lt;/docDscr&gt;
          &lt;stdyDscr&gt;
              &lt;citation&gt;
                  &lt;titlStmt&gt;
                      &lt;titl&gt;Test Title 2&lt;/titl&gt;
                      &lt;IDNo agency="UKDA"&gt;101&lt;/IDNo&gt;
                  &lt;/titlStmt&gt;
                  &lt;rspStmt&gt;
                      &lt;AuthEnty&gt;TestAuthEntry&lt;/AuthEnty&gt;
                  &lt;/rspStmt&gt;
                  &lt;prodStmt&gt;
                      &lt;copyright&gt;Yes&lt;/copyright&gt;
                  &lt;/prodStmt&gt;
                  &lt;distStmt/&gt;
                  &lt;verStmt&gt;
                      &lt;version date=""&gt;1&lt;/version&gt;
                  &lt;/verStmt&gt;
              &lt;/citation&gt;
              &lt;stdyInfo&gt;
                  &lt;subject&gt;
                      &lt;keyword&gt;2009&lt;/keyword&gt;
                      &lt;keyword&gt;2010&lt;/keyword&gt;
                      &lt;topcClas&gt;CLASS&lt;/topcClas&gt;
                      &lt;topcClas&gt;ffdsf&lt;/topcClas&gt;
                  &lt;/subject&gt;
                  &lt;abstract&gt;This is an abstract piece of text.&lt;/abstract&gt;
                  &lt;sumDscr&gt;
                      &lt;timePrd event="single"&gt;2020&lt;/timePrd&gt;
                      &lt;nation&gt;UK&lt;/nation&gt;
                      &lt;anlyUnit&gt;Test&lt;/anlyUnit&gt;
                      &lt;universe&gt;test&lt;/universe&gt;
                      &lt;universe&gt;hello&lt;/universe&gt;
                      &lt;dataKind&gt;fdsfdsf&lt;/dataKind&gt;
                  &lt;/sumDscr&gt;
              &lt;/stdyInfo&gt;
              &lt;method&gt;
                  &lt;dataColl&gt;
                      &lt;timeMeth&gt;test timemeth&lt;/timeMeth&gt;
                      &lt;dataCollector&gt;test data collector&lt;/dataCollector&gt;
                      &lt;sampProc&gt;test sampprocess&lt;/sampProc&gt;
                      &lt;deviat&gt;test deviat&lt;/deviat&gt;
                      &lt;collMode&gt;test collMode&lt;/collMode&gt;
                      &lt;sources/&gt;
                  &lt;/dataColl&gt;
              &lt;/method&gt;
              &lt;dataAccs&gt;
                  &lt;setAvail&gt;
                      &lt;accsPlac&gt;Test accsPlac&lt;/accsPlac&gt;
                  &lt;/setAvail&gt;
                  &lt;useStmt&gt;
                      &lt;restrctn&gt;NONE&lt;/restrctn&gt;
                  &lt;/useStmt&gt;
              &lt;/dataAccs&gt;
              &lt;othrStdyMat&gt;
                  &lt;relPubl&gt;122&lt;/relPubl&gt;
                  &lt;relPubl&gt;12332&lt;/relPubl&gt;
              &lt;/othrStdyMat&gt;
          &lt;/stdyDscr&gt;
      &lt;/codeBook&gt;
  &lt;/metadata&gt;
  </code></pre>
  
  <p>I wrote the following code to try and process it:</p>
  
  <pre><code>from lxml import etree
  import pdb
  
  f = open('/vagrant/out2.xml', 'r')
  xml_str = f.read()
  
  xml_doc = etree.fromstring(xml_str)
  
  f.close()
  </code></pre>
  
  <p>From what I understand from the <a href="http://lxml.de/xpathxslt.html#xpath" rel="nofollow">lxml xpath docs</a>, I should be able to get the text from a specific element as follows:</p>
  
  <pre><code>xml_doc.xpath('/metadata/codeBook/docDscr/citation/titlStmt/titl/text()')
  </code></pre>
  
  <p>However, when I run this it returns an empty array.</p>
  
  <p>The only xpath I can get to return something is using a wildcard:</p>
  
  <pre><code>xml_doc.xpath('*')
  </code></pre>
  
  <p>Which returns <code>[&lt;Element {ddi:codebook:2_5}codeBook at 0x7f8da8a413f8&gt;]</code>.</p>
  
  <p>I've read through the docs and I'm not understanding what is going wrong with this. Any help is appreciated.</p>