How to access attributes of nodes in xml.minidom
Ruediger Maehl
ruediger.maehl_nospam at web.de
Thu Apr 11 09:33:41 EDT 2002
Hello Pythoneers,
although I have tried as much as possible, I couldn't avoid that I now
have to use XML formatted files for different purposes. I just started
using the xml.minidom and I took the example and started to change
it to my needs.
But, how can I access the attributes of a node?
The documentation in the Python Library Reference is fairly short
and I cannot get further. Can anyone please help or point me to a
more extensive documentation?
Many TIA,
Rüdiger
This is my script:
#################
import xml.dom.minidom
document = """\
<slideshow>
<title attrib="new">Demo slideshow</title>
<slide>
<title>Slide title</title>
<point>This is a demo</point>
<point>Of a program for processing slides</point>
</slide>
</slideshow>
"""
def main(dom):
for node in dom.childNodes:
print node.tagName
# That's how I expected it to work, but it doesn't
for attrib in node.Attributes:
print attrib
dom = xml.dom.minidom.parseString(document)
main(dom)
dom.unlink() # minidom only?
#################
More information about the Python-list
mailing list