title: Python libxml2 XPath/Namespace Help
body: <p>I'm trying to learn how to do XPath queries from Python using this sample XML file: <a href="http://pastie.org/1333021" rel="nofollow">http://pastie.org/1333021</a> I just added a namespace to it because my actual application uses it.</p>
  
  <p>Basically, I want to execute a top level query that returns a subset of nodes and then query the subset (on a much larger scale than this example)</p>
  
  <p>So this is my code to first find all <code>&lt;food&gt;</code> nodes and then iterate over the description of each one.</p>
  
  <pre><code>#!/usr/bin/python2
  
  import libxml2
  
  doc = libxml2.parseFile("simple.xml")
  context = doc.xpathNewContext()
  
  context.xpathRegisterNs("db", "http://examplenamespace.com")
  res = context.xpathEval("//db:food")
  
  for node in res:
      # Query xmlNode here
      print "Got Food Node:"
      desc = node.xpathEval('db:description') # this is wrong?
      print desc
  </code></pre>
  
  <p>So it's essentially a namespace problem, if I remove the <code>xlns</code> attribute from the XML file and use just basic XPATH queries without <code>db:</code> it works fine. The top query <code>//db:food</code> works fine, but the second one fails evaluating.</p>
  
  <p>Please can someone correct my namespace/query syntax.</p>
  
  <p>Thanks a lot</p>