Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Does ElementTree's Parent XPath actually work?

Reply
Thread Tools

Does ElementTree's Parent XPath actually work?

 
 
Jason Cooper
Guest
Posts: n/a
 
      03-09-2012
I'm curious to know if anyone with ElementTree 1.3 has gotten the parent XPath to work? According to http://effbot.org/zone/element-xpath.htm, you should be able to do

>>> import xml.etree.ElementTree as et
>>> et.VERSION

'1.3.0'
...
>>> elem.find('..')
>>>


but that always return None for me. Has anyone else seen this particular XPath work? Am I just doing something wrong?

Thanks for you help!
Jason

PS. In case you're wondering, yes I know that lxml supports parent points and, yes, I'm aware of http://effbot.org/zone/element.htm#accessing-parents. I'm really wondering if the mentioned XPath is broken or something.
 
Reply With Quote
 
 
 
 
Jason Cooper
Guest
Posts: n/a
 
      03-09-2012
On Friday, March 9, 2012 12:24:04 PM UTC-5, Jason Cooper wrote:
> I'm curious to know if anyone with ElementTree 1.3 has gotten the parent XPath to work? According to http://effbot.org/zone/element-xpath.htm, you should be able to do
>
> >>> import xml.etree.ElementTree as et
> >>> et.VERSION

> '1.3.0'
> ...
> >>> elem.find('..')
> >>>

>
> but that always return None for me. Has anyone else seen this particular XPath work? Am I just doing something wrong?
>
> Thanks for you help!
> Jason
>
> PS. In case you're wondering, yes I know that lxml supports parent pointsand, yes, I'm aware of http://effbot.org/zone/element.htm#accessing-parents. I'm really wondering if the mentioned XPath is broken or something.


Looks like I may have figured out my own answer. I just noticed that using '..' when searching on the tree (as opposed to the element) works as expected. Makes sense after I stepped back and recalled that the elements don't contain pointers to their parents. The tree, on the other hand, can see all.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How does TinEye actually work to identify a photo (does it useEXIF?) William Don**ly Digital Photography 8 12-28-2012 01:29 PM
If a class Child inherits from Parent, how to implementChild.some_method if Parent.some_method() returns Parent instance ? metal Python 8 10-30-2009 10:31 AM
What does sender.Parent.Parent.Cells() reference? Frustrating... Roy ASP .Net 2 02-11-2005 09:00 PM
what does the native keyword do actually ? and how does it work ?when we can use it ? Alek Nazarian Java 7 10-22-2003 04:33 PM
XPath that does not include other XPath Anna XML 0 07-31-2003 07:55 AM



Advertisments