June 2000
Intermediate to advanced
556 pages
8h 45m
English
In this example, which uses the same test.xml input file as the previous example, we print the data content of an XML document by traversing the tree, isolating the text nodes, and printing their contents.
CD-ROM reference=11003.txt
C>type dom2.py """ Print text by navigating DOM nodes. """ # Import the core DOM module. from xml.dom import core # Import the DOM SAX builder. from xml.dom.sax_builder import SaxBuilder # Import the SAX modules. from xml.sax import saxexts,saxlib import sys def PrintText(nodelist): # Print the data content of a node list. for n in nodelist: if n.nodeType == core.TEXT_NODE: # For text nodes, data content is available as # the nodeValue instance variable. print n.nodeValue, elif n.nodeType ...Read now
Unlock full access