module documentation
_builder.py - XML builder for ZMS object tree construction
Implements a builder class (cp. design pattern "BUILDER") to build a tree of ZOPE objects out of an XML formatted document. Uses the class "pyexpat" (cp. module "Shared.DC.xml") for parsing the XML document. The general approach of the XML parser "pyexpat" is event driven, where handler methods are called on occurence of XML tags. Builder redirects these events to a set of own handler methods (see below). To build up the object tree, Builder provides the following functionality:
- Usually, the occurence of a XML tag induces the instanciation of a new node object. Therefore, Builder contains a mapping table ("dGlobalAttrs"), that maps XML tags to python classes. The handler method "Builder.OnStartElement()" creates a node object of the corresponding class. This node object is then made current.
- In General, events are directed to the current node object. Therefore, they have to contain a set of interface methods (see below). The node objects are responsible for handling these events. This includes the insertion into the object tree as well as the interpretation of XML tag parameters.
- A dedicated root object is managed by Builder. The root object may be predefined or created during the parsing process.
Builder is usually used as a mix-in base class for other classes. For usage, the following issues must be taken into consideration:
- Overwrite "dGlobalAttrs" with a dictionary, that maps XML-Tags to python classes.
- Call "Builder.parse()" to initiate the parsing and building process.
- Equip all python classes with the following interface methods:
- xmlOnStartElement(self, dTagName, dTagAttrs, oParentNode)
- xmlOnCharacterData(self, sData, bInCData)
- xmlOnEndElement(self)
- xmlOnUnknownStartTag(self, sTagName, dTagAttrs)
- xmlOnUnknownEndTag(self, sTagName)
- xmlGetParent(self)
License: GNU General Public License v2 or later, Organization: ZMS Publishing
| Class | |
Generic XML builder for constructing ZMS object trees. |
| Exception | |
Exception raised when XML parsing fails. |