4Suite API Documentation

Module Ft.Xml.Lib.XmlPrinter

This module supports document serialization in XML syntax.
Copyright 2005 Fourthought, Inc. (USA).
Detailed license and copyright information: http://4suite.org/COPYRIGHT
Project home, documentation, distributions: http://4suite.org/
Classes:
Functions:
Globals:

Classes

class CanonicalXmlPrinter(XmlPrinter)
CanonicalXmlPrinter emits only c14n XML. http://www.ibm.com/developerworks/xml/library/x-c14n/ http://www.w3.org/TR/xml-c14n Does not yet: * Normalize all attribute values * Specify all default attributes Note: this class is fully compatible with exclusive c14n: http://www.w3.org/TR/xml-exc-c14n/ whether or not the operation is exclusive depends on preprocessing operations appplied by the caller. See Ft.Xml.Lib.Print, for example

Methods

__init__(self, stream, encoding=None)
Overrides: __init__ from class XmlPrinter
attribute(self, elementUri, elementName, name, value)
Handles an attribute event.
Writes an attribute to the stream as a space followed by
the name, '=', and quote-delimited value. It is the caller's
responsibility to ensure that this is called in the correct
context, if well-formed output is desired.

The delimiter is always a quote ("), as required by c14n
The elementName arguments are not used by default,
but may be used by subclasses.
Overrides: attribute from class XmlPrinter
cdataSection(self, data)
Handles a cdataSection event.
No CDATA sections in c14n, so just commute to the text event
Overrides: cdataSection from class XmlPrinter
comment(self, data)
Handles a comment event.
Writes a comment to the stream.
Overrides: comment from class XmlPrinter
doctype(self, name, publicId, systemId)
Handles a doctype event. No output in c14n.
Overrides: doctype from class XmlPrinter
endDocument(self)
Writes any necessary final output to the stream.
Overrides: endDocument from class XmlPrinter
endElement(self, namespaceUri, tagName)
Handles an endElement event.
Writes the closing tag for an element to the stream.
The namespaceUri argument is ignored in this class.
Overrides: endElement from class XmlPrinter
processingInstruction(self, target, data)
Handles a processingInstruction event.
Writes a processing instruction to the stream.
Overrides: processingInstruction from class XmlPrinter
reset(self)
Sets the writer state as if it were a brand new instance
Overrides: reset from class XmlPrinter
startDocument(self, version='1.0', standalone=None)
No XML declaration is generated
Overrides: startDocument from class XmlPrinter
startElement(self, namespaceUri, tagName, namespaces, attributes)
Handles a startElement event.
Writes part of an element's start-tag or empty-element tag to
the stream, and closes the start tag of the previous element,
if one remained open. Writes the xmlns attributes for the given
dictionary of namespaces, and invokes attribute() as neeeded to
write the given dictionary of attributes.

The namespaceUri argument is ignored in this class.
Overrides: startElement from class XmlPrinter
text(self, text, disableEscaping=0)
Handles a text event.
Writes character data to the stream.  All characters should be
suitable for encoding (UTF-8 only); "&" and "<" are escaped as "&amp;"
and "&lt;"; and ">" is escaped as "&gt;" if it is preceded by
"]]".

disableEscaping is ignored.
Overrides: text from class XmlPrinter

Members

attrEntitiesApos = <cEntityMap>
attrEntitiesQuot = <cEntityMap>
attrNormPattern = <_sre.SRE_Pattern object>
textEntities = <cEntityMap>
class XmlPrinter
An XmlPrinter instance provides functions for serializing an XML or XML-like document to a stream, based on SAX-like event calls initiated by an Ft.Xml.Lib.Print.PrintVisitor instance.
The methods in this base class attempt to emit a well-formed parsed
general entity conformant to XML 1.0 syntax, with no extra
whitespace added for visual formatting. Subclasses may emit
documents conformant to other syntax specifications or with
additional whitespace for indenting.

The degree of well-formedness of the output depends on the data
supplied in the event calls; no checks are done for conditions that
would result in syntax errors, such as two attributes with the same
name, "--" in a comment, etc. However, attribute() will do nothing
if the previous event was not startElement(), thus preventing
spurious attribute serializations.

Methods

__init__(self, stream, encoding)
stream must be a file-like object open for writing binary data. encoding specifies the encoding which is to be used for writing to the stream.
attribute(self, elementUri, elementName, name, value)
Handles an attribute event.
Writes an attribute to the stream as a space followed by
the name, '=', and quote-delimited value. It is the caller's
responsibility to ensure that this is called in the correct
context, if well-formed output is desired.

Preference is given to quotes (") around attribute values, in
accordance with the DomWriter interface in DOM Level 3 Load and
Save (25 July 2002 WD), although a value that contains quotes
but no apostrophes will be delimited by apostrophes (') instead.
The elementName arguments are not used by default,
but may be used by subclasses.
cdataSection(self, data)
Handles a cdataSection event.
Writes character data to the stream as a CDATA section.
comment(self, data)
Handles a comment event.
Writes a comment to the stream.
doctype(self, name, publicId, systemId)
Handles a doctype event.
Writes a document type declaration to the stream.
endDocument(self)
Handles an endDocument event.
Writes any necessary final output to the stream.
endElement(self, namespaceUri, tagName)
Handles an endElement event.
Writes the closing tag for an element to the stream, or, if the
element had no content, finishes writing the empty element tag.

The namespaceUri argument is ignored in this class.
processingInstruction(self, target, data)
Handles a processingInstruction event.
Writes a processing instruction to the stream.
reset(self)
Sets the writer state as if it were a brand new instance
startDocument(self, version='1.0', standalone=None)
Handles a startDocument event.
Writes XML declaration or text declaration to the stream.
startElement(self, namespaceUri, tagName, namespaces, attributes)
Handles a startElement event.
Writes part of an element's start-tag or empty-element tag to
the stream, and closes the start tag of the previous element,
if one remained open. Writes the xmlns attributes for the given
dictionary of namespaces, and invokes attribute() as neeeded to
write the given dictionary of attributes.

The namespaceUri argument is ignored in this class.
text(self, text, disableEscaping=0)
Handles a text event.
Writes character data to the stream. If the disableEscaping flag
is not set, then unencodable characters are replaced with
numeric character references; "&" and "<" are escaped as "&amp;"
and "&lt;"; and ">" is escaped as "&gt;" if it is preceded by
"]]". If the disableEscaping flag is set, then the characters
are written to the stream with no escaping of any kind, which
will result in an exception if there are unencodable characters.

Members

attrEntitiesApos = <cEntityMap>
attrEntitiesQuot = <cEntityMap>
textEntities = <cEntityMap>

Functions

SplitQName(qualifiedName)
SplitQName(qualifiedName) -> (prefix, localName)
where 'qualifiedName' is a QName according to XML Namespaces 1.0
<http://www.w3.org/TR/REC-xml-names>.
returns the name parts according to the spec.

Globals

XMLNS_NAMESPACE = u'http://www.w3.org/2000/xmlns/'