Does ElementTree's Parent XPath actually work?

Discussion in 'Python' started by Jason Cooper, Mar 9, 2012.

  1. Jason Cooper

    Jason Cooper Guest

    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.
    Jason Cooper, Mar 9, 2012
    #1
    1. Advertising

  2. Jason Cooper

    Jason Cooper Guest

    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.
    Jason Cooper, Mar 9, 2012
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alek Nazarian
    Replies:
    7
    Views:
    3,221
    Alek Nazarian
    Oct 22, 2003
  2. Karl
    Replies:
    3
    Views:
    351
  3. John Nagle

    Does class patching actually work

    John Nagle, Jan 16, 2007, in forum: Python
    Replies:
    2
    Views:
    280
    John Nagle
    Jan 17, 2007
  4. Kee Nethery
    Replies:
    12
    Views:
    2,073
    Stefan Behnel
    Jun 27, 2009
  5. Steven D'Aprano

    Does turtledemo in Python 3.2 actually work?

    Steven D'Aprano, Feb 24, 2012, in forum: Python
    Replies:
    2
    Views:
    402
    Terry Reedy
    Feb 24, 2012
Loading...

Share This Page