a few more questions on XML and python

stalin woodsplitter at rocketmail.com
Fri Jan 4 12:31:03 CET 2002

Rajarshi Guha <rxg218 at psu.edu> wrote:

> Where can I look up the methods available and the actual tree structuire? I 
> tried reading the actual .py file but I got all mixed up - is there any 
> reference to the available methods.?

  The standard library documentation, section 13.6 "xml.dom" describes
the library's DOM support and has links to the W3C DOM specification. 
In particular, 13.6.2 "Objects in the DOM" is probably what you're
looking for when you say "reference to the available methods":

> I do have another question - how can I traverse the tree and see what 
> available tags got read in?

from StringIO import StringIO
import xml.dom.minidom as dom

theXML = """<?xml version="1.0"?>
<book edition="1">
    <title>The Fascist Menace</title>
            <email>unclejoe at kremlin.ru</email>
            <email>just-another-tovarisch at kremlin.ru</email>
    <description><![CDATA[Our fearless leader's electrifying call to

def printTagNames(node, indentationLevel=0):
    print indentationLevel * ' ' + node.tagName

    for child in node.childNodes:
        if child.nodeType == dom.Node.ELEMENT_NODE:
            printTagNames(child, indentationLevel+4)

doc = dom.parse(StringIO(theXML))

print '--- TAG DUMP ---'

More information about the Python-list mailing list