9.1. Modelling a Node

In figure 9-1, element nodes are represented by ellipses, and data nodes are represented by rectangles. Although they are clearly different types of node, they share some common characteristics, namely, they can be linked top, bottom, left, and right to other nodes.

The fact that the two node types are different yet share some common characteristics points strongly to an implemention that involves a class hierarchy. The base of the hierarchy will be the xNode class, as shown below.

CD-ROM reference=9002.txt
class xNode:
      def __init__(self):
            self.Up = self.Down = self.Left = self.Right = None

Element nodes can be implemented as a subclass of xNode called xElement. Objects of type xElement will inherit the pointers to Up ...

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.