Confusion over etree.ElementTree.Element.getiterator

B

Ben Sizer

It seems that getiterator isn't returning the tags I ask for.
.... 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>
0

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?
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.
 
S

Stefan Behnel

Ben Sizer, 04.07.2010 00:32:
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
 
B

Ben Sizer

BenSizer, 04.07.2010 00:32:
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! :)
 
T

Terry Reedy

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.
 
A

Aahz

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top