Quantcast

help getting started with xpath

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

help getting started with xpath

Bo Laurent-2
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">
     <types>
         <members>*</members>
         <name>CustomObject</name>
     </types>
     <version>16.0</version>
</Package>

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
lxml-2.2-py2.5-macosx-10.3-i386.egg
OSX 10.5.7



_______________________________________________
XML-SIG maillist  -  [hidden email]
http://mail.python.org/mailman/listinfo/xml-sig
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: help getting started with xpath

Stefan Behnel-3


Bo Laurent wrote:
> 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?

Yes, exactly. See here:

http://codespeak.net/lxml/xpathxslt.html#xpath

Stefan
_______________________________________________
XML-SIG maillist  -  [hidden email]
http://mail.python.org/mailman/listinfo/xml-sig
Loading...