ProjectPythonSourceForge
Welcome
Introduction
Suitability
Future Plans
Setup
Downloading XMLObject
Installing XMLObject
XMLObjApp
The XMLObjApp Application
Classes
Special Attributes
XML Attributes
Child Tags
File Menu
Miscellaneous Operation Notes
Unicode and ASCII Strings
Manually Editing Your Parser
Outputting XML
XMLObject
XMLObject -- XML to Object Conversion
Stack -- Tracks the Document Hierarchy
Object Interface
Examples
All Docs on One Page

XMLObject -- XML to Object Conversion

This module helps represent XML with a more "natural" set of object instances.

It defines the following members:

XMLStructError(exception)

XMLStructError is an Exception thrown when an XML file differs from the structure allowed by the parser. exception is a text message describing what went wrong.

Stack

Stack is a class used to track an element's relationship to the rest of the document. Stack is passed to element constructors during XML parsing.

ChildClass(Dict, Validator)

ChildClass is a class used to describe what children an element may have. ChildClass is stored in a class member called ChildSpec.

Dict is dictionary mapping of tags to classes that are allowed as children for this particular element. Keys should be text strings such as "Tag", and not a VCD-ish variant such as "<Tag>". Values should be an instance of either PCDATAChild, XMLChild, or StdChild.

Validator is the element's VCD string. See VCD Strings for more information on creating VCD strings.

PCDATAChild(Processing, Attr[, Delimiter])

PCDATAChild defines how the #PCDATA pseudo-tag should be configured. PCDATAChild instances are stored in the element's ChildSpec.

Processing is a string indicating how the text should be processed. Processing should have one of the following constant values: "Strip", "Exact", "Split", "Strip-Split", "Split-Strip", or "Strip-Split-Strip". See Configuring a #PCDATA Child Type for more information on processing text strings.

Attr is a string indicating which attribute of the class instance should receive the text.

Delimiter is a string used to split text strings into a list. Delimiter is only signifigant if Processing is set to "Split", "Strip-Split", "Split-Strip", or "Strip-Split-Strip".

XMLChild(Processing, Attr)

XMLChild configures how the <XML> pseudo-tag should be configured. XMLChild instances are stored in the element's ChildSpec.

Processing is a string indicating how the XML should be processed. Processing should either be "Strip" or "Exact".

Attr is a string indicating which attribute of the class instance should receive the XML text.

StdChild(Class[, Attr][, Save][, Key][, Reduce])

StdChild configures how the standard tags should be configured. StdChild instances are stored in the element's ChildSpec.

Class is the class to instantiate when this child is parsed.

Attr is a string indicating which attribute of the class instance should receive the new instance.

Save is a string indicating how the child should be saved. Save should either be "Single", "List" or "Dict". See Configuring a Typical Child Type for more information on saving children.

Key is the class member used as dictionary key. Key is only signifigant if Save is set to "Dict".

Reduce is the class member to reduce to. No reduction will be done if this member is left unset or is set to None.

Parse(FilenameOrStream, RootTag, RootClass, [XMLStack])

Parse is a function that parses XML from a file or stream represented by FilenameOrStream and returns the document's root object.

RootTag is a text string representing the expected, top-most tag in the XML file or stream. It should be the name of the tag only, such as "Root", and not a VCD-ish variant such as "<Root>". If the top-most tag is anything other than RootTag, then XMLObject will raise an XMLStructError exception.

RootClass is the class to instantiate for the top-most element in the XML file or stream.

XMLStack is optional. You can create an empty Stack instance yourself and pass it in to Parse as XMLStack. You should only need to do this if you plan to find elements by their UniqueID, and you don't know where in the document hierarchy they will be located. See Example 5.3, “Searching a Stack Instance”.