import sys
import libxml2

if len(sys.argv) < 3:
    raise Exception("Usage: %s xpath file" % sys.argv[0])
xpath_text = sys.argv[1]
filename = sys.argv[2]
document = libxml2.parseFile(filename)
if document.name != filename:
    print "document.name error on %s" % filename
    sys.exit(1);
context = document.xpathNewContext()
result = context.xpathEval(xpath_text)
if len(result) == 0:
    raise Exception("No %s found in %s" % (xpath_text, filename))
for node in result:
    print node.content
    

