[XML-SIG] help getting started with xpath

Bo Laurent bo.laurent at canonical.com
Tue Jul 21 10:59:31 CEST 2009

I'm new to lxml. I've parsed a simple document, as shown below.  But I  
every simple xpath() expression I try returns empty list. What am I  
doing wrong? Perhaps I need to spec the namespace to the parser?

<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">

self.doc = etree.parse( self.package_xml_path )

(Pdb) root = self.doc.getroot()
(Pdb) root.getchildren()
[<Element {http://soap.sforce.com/2006/04/metadata}types at e1dc60>,  
<Element {http://soap.sforce.com/2006/04/metadata}version at e1dc90>]
(Pdb) root.xpath('//Package')
(Pdb) root.xpath('/Package')
(Pdb) root.xpath('Package')
(Pdb) root.xpath('types')
(Pdb) root.xpath('/types')

===== environment ====
Python 2.5.2
OSX 10.5.7

More information about the XML-SIG mailing list