11.6. Walking a DOM Tree

The pyDOM package provides a number of utilities for processing DOM trees over and above what the DOM spec specifies. One of the most useful is the Walker class, which simplifies the process of walking an entire tree structure in top-down, left-to-right order.

In the example below, a class derived from Walker generates a subset of PYX from a DOM tree.

 CD-ROM reference=11004.txt """ Walk a DOM Tree, generating PYX. """ # Import core DOM. from xml.dom import core # Import DOM walker utility class. from xml.dom.walker import Walker # Import DOM SAX builder. from xml.dom.sax_builder import SaxBuilder import string,sys # Import SAX. from xml.sax import saxexts,saxlib def Encode(s): """ Function to escape newlines for PYX ...

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.