Package gavo :: Package utils :: Module stanxml
[frames] | no frames]

Module stanxml

source code

A stan-like model for building namespaced XML trees.

The main reason for this module is that much of the VO's XML mess is based on XML schema and thus has namespaced attributes. This single design decision ruins the entire XML design. To retain some rests of sanity, I treat the prefixes themselves as namespaces and maintain a single central registry from prefixes to namespaces in this module.

Then, the elements only use these prefixes, and this module makes sure that during serialization the instance document's root element contains the namespace mapping (and the schema locations) required.

Classes
  Error
  ChildNotAllowed
  Stub
A sentinel class for embedding objects not yet existing into stanxml trees.
  Element
An element for serialization into XML.
  NSRegistry
A container for a registry of namespace prefixes to namespaces.
  DOMMorpher
An object encapsulating the process of turning a stanxml.Element tree into an ElementTree.
  NillableMixin
An Element mixin making the element XSD nillable.
Functions
 
schemaURL(xsdName)
returns the URL to the local mirror of the schema xsdName.
source code
 
escapePCDATA(val) source code
 
escapeAttrVal(val) source code
 
write(root, outputFile, prefixForEmpty=None, nsRegistry=<class 'gavo.utils.stanxml.NSRegistry'>, xmlDecl=True, includeSchemaLocation=True)
writes an xmlstan tree starting at root to destFile.
source code
 
xmlrender(tree, prolog=None, prefixForEmpty=None)
returns a unicode object containing tree in serialized forms.
source code
Variables
  encoding = 'utf-8'
  XML_HEADER = '<?xml version="1.0" encoding="utf-8"?>'
  xsiPrefix = frozenset(['xsi'])
  __package__ = 'gavo.utils'
Function Details

schemaURL(xsdName)

source code 

returns the URL to the local mirror of the schema xsdName.

This is used by the various xmlstan clients to make schemaLocations.

write(root, outputFile, prefixForEmpty=None, nsRegistry=<class 'gavo.utils.stanxml.NSRegistry'>, xmlDecl=True, includeSchemaLocation=True)

source code 

writes an xmlstan tree starting at root to destFile.

prefixForEmpty is a namespace URI that should have no prefix at all.

xmlrender(tree, prolog=None, prefixForEmpty=None)

source code 

returns a unicode object containing tree in serialized forms.

tree can be any object with a render method or some sort of string. If it's a byte string, it must not contain any non-ASCII.

If prolog is given, it must be a string that will be prepended to the serialization of tree. The way ElementTree currently is implemented, you can use this for xml declarations or stylesheet processing instructions.