FAQ
It seems that getiterator isn't returning the tags I ask for.
tree = parse('gdlibs.html')
root = tree.getroot()
for el in root.getiterator():
... print el
[much output snipped]
<Element {http://www.w3.org/1999/xhtml}a at d871e8>
<Element {http://www.w3.org/1999/xhtml}a at d87288>
<Element {http://www.w3.org/1999/xhtml}script at d87300>
<Element {http://www.w3.org/1999/xhtml}script at d87378>
it = root.getiterator('script')
all_scripts = list(it)
print len(all_scripts)

I would have expected at least 2 script tags to be found, considering
iterating over the whole lot found at least 2 at the end there.

What am I doing wrong?
import sys
print sys.version
2.6.4 (r264:75708, Oct 26 2009, 08:23:19) [MSC v.1500 32 bit (Intel)]


I will upgrade to 2.6.5 ASAP, but I don't see anything in the
changelog that implies a bug that has been fixed here.

--
Ben Sizer

Search Discussions

  • Ben Sizer at Jul 3, 2010 at 10:32 pm

    On Jul 3, 11:12?pm, Ben Sizer wrote:

    for el in root.getiterator():
    ... ? ? ? ?print el
    [much output snipped]
    <Element {http://www.w3.org/1999/xhtml}a at d871e8>
    <Element {http://www.w3.org/1999/xhtml}a at d87288>
    <Element {http://www.w3.org/1999/xhtml}script at d87300>
    <Element {http://www.w3.org/1999/xhtml}script at d87378>
    Hmm, I think I've worked it out. Apparently the XML namespace forms
    part of the tag name in this case. Is that what is intended? I didn't
    see any examples of this in the docs.

    --
    Ben Sizer
  • Stefan Behnel at Jul 4, 2010 at 6:33 am

    Ben Sizer, 04.07.2010 00:32:
    On Jul 3, 11:12 pm, Ben Sizerwrote:
    for el in root.getiterator():
    ... print el
    [much output snipped]
    <Element {http://www.w3.org/1999/xhtml}a at d871e8>
    <Element {http://www.w3.org/1999/xhtml}a at d87288>
    <Element {http://www.w3.org/1999/xhtml}script at d87300>
    <Element {http://www.w3.org/1999/xhtml}script at d87378>
    Hmm, I think I've worked it out. Apparently the XML namespace forms
    part of the tag name in this case. Is that what is intended?
    Sure.

    I didn't see any examples of this in the docs.
    Admittedly, it's three clicks away from the library docs on docs.python.org.

    http://effbot.org/zone/element.htm#xml-namespaces

    Stefan
  • Ben Sizer at Jul 5, 2010 at 10:40 am

    On Jul 4, 7:33?am, Stefan Behnel wrote:
    BenSizer, 04.07.2010 00:32:
    On Jul 3, 11:12 pm,BenSizer<kylo... at gmail.com> ?wrote:
    for el in root.getiterator():
    ... ? ? ? ?print el
    [much output snipped]
    <Element {http://www.w3.org/1999/xhtml}a at d871e8>
    <Element {http://www.w3.org/1999/xhtml}a at d87288>
    <Element {http://www.w3.org/1999/xhtml}script at d87300>
    <Element {http://www.w3.org/1999/xhtml}script at d87378>
    Hmm, I think I've worked it out. Apparently the XML namespace forms
    part of the tag name in this case. Is that what is intended? Sure.
    I didn't see any examples of this in the docs.
    Admittedly, it's three clicks away from the library docs on docs.python.org.

    http://effbot.org/zone/element.htm#xml-namespaces
    Hopefully someone will see fit to roll this important documentation
    into docs.python.org before the next release... oops, too late. ;)

    It's one of those things that's easy to fix when you know what the
    problem is. Unfortunately it makes the examples a bit awkward. The
    example on http://docs.python.org/library/xml.etree.elementtree.html
    opens up an xhtml file and reads a "p" tag within a "body" tag, but
    the xhtml specification (http://www.w3.org/TR/xhtml1/#strict) states
    that 'The root element of the document must contain an xmlns
    declaration for the XHTML namespace'. Therefore I don't see how the
    example Python code given could work on a proper xhtml file, given
    that there should always be a namespace in effect but the code doesn't
    allow for it.

    That's my excuse anyway! :)

    --
    Ben Sizer
  • Terry Reedy at Jul 5, 2010 at 6:09 pm

    On 7/5/2010 6:40 AM, Ben Sizer wrote:

    Admittedly, it's three clicks away from the library docs on docs.python.org.

    http://effbot.org/zone/element.htm#xml-namespaces
    Hopefully someone will see fit to roll this important documentation
    into docs.python.org before the next release... oops, too late. ;)
    Not too late for next release. Open a doc issue with as specific a
    suggestion as possible.
    It's one of those things that's easy to fix when you know what the
    problem is. Unfortunately it makes the examples a bit awkward. The
    example on http://docs.python.org/library/xml.etree.elementtree.html
    opens up an xhtml file and reads a "p" tag within a "body" tag, but
    the xhtml specification (http://www.w3.org/TR/xhtml1/#strict) states
    that 'The root element of the document must contain an xmlns
    declaration for the XHTML namespace'. Therefore I don't see how the
    example Python code given could work on a proper xhtml file, given
    that there should always be a namespace in effect but the code doesn't
    allow for it.

    That's my excuse anyway! :)

    --
    Terry Jan Reedy
  • Aahz at Jul 6, 2010 at 2:15 pm
    In article <mailman.267.1278353389.1673.python-list at python.org>,
    Terry Reedy wrote:
    On 7/5/2010 6:40 AM, Ben Sizer wrote:

    Admittedly, it's three clicks away from the library docs on docs.python.org.

    http://effbot.org/zone/element.htm#xml-namespaces
    Hopefully someone will see fit to roll this important documentation
    into docs.python.org before the next release... oops, too late. ;)
    Not too late for next release. Open a doc issue with as specific a
    suggestion as possible.
    Actually, it's not too late for this release, either (or at least it
    used not to be): the docs on the website can be updated even if the
    downloadable package itself can't be.
    --
    Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/

    "If you don't know what your program is supposed to do, you'd better not
    start writing it." --Dijkstra

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedJul 3, '10 at 10:12p
activeJul 6, '10 at 2:15p
posts6
users4
websitepython.org

People

Translate

site design / logo © 2022 Grokbase