title: Appropriate xpath syntax with python for non-standard xml
body: <p>The input file is actually multiple XML files appending to one file. (Sourced from <a href="http://commondatastorage.googleapis.com/patents/grant_full_text/2010/ipg100105.zip" rel="nofollow">Google Patents</a>). This is an example:</p>
  
  <blockquote>
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;!DOCTYPE us-patent-grant SYSTEM "us-patent-grant-v42-2006-08-23.dtd" [ ]&gt;
  &lt;us-patent-grant lang="EN" dtd-version="v4.2 2006-08-23"&gt;
  &lt;applicants&gt;
  &lt;applicant sequence="001" app-type="applicant-inventor" designation="us-only"&gt;
  &lt;addressbook&gt;&lt;last-name&gt;Beyer&lt;/last-name&gt;
  &lt;first-name&gt;Daniel Lee&lt;/first-name&gt;
  &lt;address&gt;&lt;city&gt;Franklin&lt;/city&gt;
  &lt;state&gt;TN&lt;/state&gt;
  &lt;country&gt;US&lt;/country&gt;&lt;/address&gt;&lt;/addressbook&gt;
  &lt;nationality&gt;&lt;country&gt;omitted&lt;/country&gt;&lt;/nationality&gt;
  &lt;residence&gt;&lt;country&gt;US&lt;/country&gt;&lt;/residence&gt;
  &lt;/applicant&gt;
  &lt;applicant sequence="002" app-type="applicant-inventor" designation="us-only"&gt;
  &lt;addressbook&gt;&lt;last-name&gt;Friedland&lt;/last-name&gt;
  &lt;first-name&gt;Jason Michael&lt;/first-name&gt;
  &lt;address&gt;&lt;city&gt;Franklin&lt;/city&gt;
  &lt;state&gt;TN&lt;/state&gt;
  &lt;country&gt;US&lt;/country&gt;&lt;/address&gt;&lt;/addressbook&gt;
  &lt;nationality&gt;&lt;country&gt;omitted&lt;/country&gt;&lt;/nationality&gt;
  &lt;residence&gt;&lt;country&gt;US&lt;/country&gt;&lt;/residence&gt;
  &lt;/applicant&gt;
  &lt;/applicants&gt;
  &lt;/us-patent-grant&gt;
  &lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;!DOCTYPE us-patent-grant SYSTEM "us-patent-grant-v42-2006-08-23.dtd" [ ]&gt;
  </code></pre>
  </blockquote>
  
  <p>I'm trying to create a string with a <code>"-".join</code> xpath for all of the children and grandchildren within <code>&lt;applicant&gt;</code> using the following in python with lxml:</p>
  
  <pre><code>import urllib2, os, zipfile
  from lxml import etree
  count = 0
  for item in xmlSplitter(zf.open(xml_file)):
    count += 1
    if count &gt; 1: break
    doc = etree.XML(item)
    docID = "-".join(doc.xpath('//publication-reference/document-id/*/text()'))
    title = first(doc.xpath('//invention-title/text()'))
    applicant = "-".join(doc.xpath('//applicants/applicant/*/text()'))
    print "DocID:    {0}\nTitle:    {1}\nApplicant: {2}\n".format(docID,title,applicant)
    outFile.write(str(docID) +"|"+ str(title) +"|"+ str(applicant) +"\n")
  </code></pre>
  
  <p>I've tried mutliple <a href="http://www.w3.org/TR/xpath/#path-abbrev" rel="nofollow">xpath combinations</a> but I can't produce a string with hyphens for <code>&lt;applicants&gt;</code> and while <em>/</em>/text() cant get to the grandchild it doesn't help with the stringing. What is the appropriate xpath syntax to select all text within the children and grandchildren of <code>&lt;applicant&gt;</code> and still punch it out in a string? While not shown in this example is there a way to ignore unicode that might be present at the beginning of a text line too (I believe it appears in some of the later xml docs)?  The 'applicant' output I'm hoping to get should look something like: </p>
  
  <pre><code>Beyer-Daniel Lee-Franklin-TN-US-omitted-US-Friedland-Jason Michael-Franklin-TN-US-omitted-US
  </code></pre>