Package gavo :: Package base :: Module xmlstruct
[frames] | no frames]

Module xmlstruct

source code

Code to parse structures from XML sources.

The purpose of much of the mess here is to symmetrized XML attributes and values. Basically, we want start, value, end events whether or not a piece of data comes in an element with a certain tag name or via a named attribute.

Classes
  EventProcessor
A dispatcher for parse events to structures.
Functions
 
feedTo(rootStruct, eventSource, context, feedInto=False)
feeds events from eventSource to rootStruct.
source code
 
parseFromStream(rootStruct, inputStream, context=None)
parses a tree rooted in rootStruct from some file-like object inputStream.
source code
 
parseFromString(rootStruct, inputString, context=None)
parses a DaCHS RD tree rooted in ``rootStruct`` from a string.
source code
Variables
  ALL_WHITESPACE = re.compile(r'\s*$')
  __package__ = 'gavo.base'
Function Details

feedTo(rootStruct, eventSource, context, feedInto=False)

source code 

feeds events from eventSource to rootStruct.

A new event processor is used for feeding. No context exit functions are run.

The processed root structure is returned.

if feedInto is true, the event creating the root structure is not expected (TODO: this is crap; fix it so that this is always the case when rootStruct is an instance).

parseFromStream(rootStruct, inputStream, context=None)

source code 

parses a tree rooted in rootStruct from some file-like object inputStream.

It returns the root element of the resulting tree. If rootStruct is a type subclass, it will be instanciated to create a root element, if it is an instance, this instance will be the root.

parseFromString(rootStruct, inputString, context=None)

source code 

parses a DaCHS RD tree rooted in ``rootStruct`` from a string.

It returns the root element of the resulting tree. You would use this like this:

       parseFromString(rscdef.Column, "<column name='foo'/>")