11.4. Accessing an XML File with pyDOM

The DOM specification purposely says nothing about the creation of the hierarchical data it provides access to. When the source is XML, one good way to load the DOM is through SAX events. In the program below, a SAX parser creates a DOM tree which then re-creates the XML document as output.

CD-ROM reference=11001.txt
C>type dom1.py """ Create a DOM tree structure from an XML file, using a SAX parser. """ # Import the core DOM module. from xml.dom import core # Import the SAX DOM builder. from xml.dom.sax_builder import SaxBuilder # Import the SAX modules. from xml.sax import saxexts,saxlib import sys # Create a SAX parser. p = saxexts.make_parser() # Create a SAX document handler which will build the DOM ...

Get XML Processing with Python now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.