title: Get parent node using child node lxml python
body: <p>For this <code>xml</code>,</p>
  
  <pre><code> xmldata="""
      &lt;locations&gt;
  
      &lt;continent region="Africa" &gt;
          &lt;country id="84" countryname="Algeria" &gt;&lt;/country&gt;
      &lt;/continent&gt;
  
      &lt;continent region="Asia" &gt;
          &lt;country id="84" countryname="India" &gt;&lt;/country&gt;
      &lt;/continent&gt;
  
      &lt;continent region="America" &gt;
          &lt;country id="84" countryname="Mexico" &gt;&lt;/country&gt;
      &lt;/continent&gt;
  
  &lt;/locations&gt;
  """
  </code></pre>
  
  <p>I am trying to get region name using country name , If country name is <code>India</code> then code should return <code>Asia</code>.</p>
  
  <p>What I have tried ,</p>
  
  <pre><code>import lxml.etree as ET
  root = ET.fromstring(xmldata)
  flag=False
  continent=""
  country=""
  for neighbor in root.iter('continent'):
      for i in neighbor.iter("country"):
          if i.attrib.get('countryname')=="India":
              flag=True
              continent=neighbor.attrib.get('region')
              country=i.attrib.get('countryname')
      if flag==True:
          break
  print 'Continent is ',continent , 'And country is ', country
  </code></pre>
  
  <p>This code works , but it is not convenient way to do this.</p>
  
  <p>How can i achieve this using <code>xpath</code> expression ?</p>