9.4. Building an xTree By Using PYX

Building xTree objects programmatically is useful for testing but not much fun. What we need is an algorithm that will read PYX format and create an xTree from it. This algorithm works by keeping track of the current position in the tree as the tree is built from PYX events. A variable known as PasteDown keeps track of the direction in which new nodes should be appended to the tree, that is, beneath the current node (PasteDown == 1) or to the right of the current node (PasteDown == 0).

 CD-ROM reference=9017.txt def PYX2xTree(self,f): # Use a stream of PYX to create a tree structure. # Create a temporary root node. self.RootNode = xElement("TEMP") # Set the current position to the root node. self.CurPos = self.RootNode ...

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.