Next / Previous / Contents / Shipman's homepage

6. Generic node readers and writers: .readNode() and .writeNode()

Throughout this module are classes that correspond to nodes in the XML document tree. Each such class will typical contain a static .readNode() method that converts a DOM tree Element node into a class instance, and a regular (non-static) .writeNode() method that converts the content of an instance back into a DOM Element node.

Because all these functions have the same interface, we define those interfaces here. The et module is the lxml.etree module.

    .readNode(node):   # Static method
      [ node is an et.Element node ->
          if node conforms to birdnotes.rnc ->
            return a new class instance that represents that node
          else -> raise IOError ]
    .writeNode(parent):
      [ parent is an et.Element instance ->
          parent  :=  parent with a new et.Element added
                      representing self
          return that new et.Element ]