4Suite™ API Documentation

# ► Module Ft.Xml

Things commonly needed by many modules in Ft.Xml
Copyright 2005 Fourthought, Inc. (USA).
Detailed license and copyright information: http://4suite.org/COPYRIGHT
Project home, documentation, distributions: http://4suite.org/

Classes: MarkupWriter, ReaderException, XIncludeException |  |  |  | Functions: ApplyXUpdate, SplitQName |  |  |  | Fields: EMPTY_NAMESPACE, EMPTY_PREFIX, HAS_PYEXPAT, READ_EXTERNAL_DTD, XHTML_NAMESPACE, XMLNS_NAMESPACE, XML_NAMESPACE

## Modules

MarkupWriter | General-purpose utility class for generating XML (may eventually be expanded to produce more output types)

## Classes

class MarkupWriter(__builtin__.object)
General-purpose utility class for generating XML (may eventually be expanded to produce more output types)
Sample usage:
from Ft.Xml import MarkupWriter
writer = MarkupWriter(indent=u"yes")
writer.startDocument()
writer.startElement(u'xsa')
writer.startElement(u'vendor')
#Element with simple text (#PCDATA) content
writer.simpleElement(u'name', content=u'Centigrade systems')
#Note writer.text(content) still works
writer.simpleElement(u'email', content=u"info@centigrade.bogus")
writer.endElement(u'vendor')
#Element with an attribute
writer.startElement(u'product', attributes={u'id': u"100\u00B0"})
#Note writer.attribute(name, value, namespace=None) still works
writer.simpleElement(u'name', content=u"100\u00B0 Server")
#XML fragment
writer.xmlFragment('<version>1.0</version><last-release>20030401</last-release>')
#Empty element
writer.simpleElement(u'changes')
writer.endElement(u'product')
writer.endElement(u'xsa')
writer.endDocument()
Note on the difference between 4Suite writers and printers
Writer - module that exposes a broad public API for building output
bit by bit
Printer - module that simply takes a DOM and creates output from it
as a whole, within one API invokation

### Methods

__getattr__(self, value)
__init__(self, stream=<open file '<stdout>', mode 'w' at 0x48417068>, **wargs)
Convenience factory function for Markup writers (based on xsl:output in XSLT)
simpleElement(self, tagName, namespace=None, extraNss=None, attributes=None, content=u'')
Create a simple tag with optional attributes and content. The complete element, start tag, optional text content, end tag, will all be generated by this one call. Must *not* be matched with an endElement call
tagName - qualified name of the element (must be unicode)
namespace - optional namespace URI
attribute - optional dictionary mapping name to unicode value
the name can either be a unicode QName or a tuple
of (QName, namespace URI)
content - optional unicode object with the text body of the
simple element
startElement(self, tagName, namespace=None, extraNss=None, attributes=None)
Create a start tag with optional attributes. Must eventually be matched with an endElement call
tagName - qualified name of the element (must be unicode)
namespace - optional namespace URI
attribute - optional dictionary mapping name to unicode value
the name can either be a unicode QName or a tuple
of (QName, namespace URI)
xmlFragment(self, fragment)
Incorporate a well-formed general entity into the output. fragment of fragment - string (must not be a Unicode object) to be incorporated verbatim into the output, after testing for wellp-formedness

### Methods inherited from class __builtin__.object

__delattr__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __str__

### Fields

__dict__ = <attribute '__dict__' of 'MarkupWriter' objects>
dictionary for instance variables (if defined)
__weakref__ = <attribute '__weakref__' of 'MarkupWriter' objects>
list of weak references to the object (if defined)

### Fields

class ReaderException(Ft.FtException)
Exception class for errors specific to XML reading (at a level above standard, non-namespace-aware parsing)

### Methods

__init__(self, errorCode, *args)

### Methods inherited from class Ft.FtException

__getattr__, __repr__, __str__

### Methods inherited from class exceptions.Exception

__getitem__

### Fields

INVALID_XMLNS = 201
RECURSIVE_PARSE_ERROR = 101
XMLNS_DUPLICATE_ATTRS = 202
XMLNS_UNKNOWN_PREFIX = 200
XML_PARSE_ERROR = 100

class XIncludeException(Ft.FtException)
Exception class for errors specific to XInclude processing

### Methods

__init__(self, errorCode, *args)

### Methods inherited from class Ft.FtException

__getattr__, __repr__, __str__

### Methods inherited from class exceptions.Exception

__getitem__

### Fields

INVALID_PARSE_ATTR = 11
MISSING_HREF = 10

## Functions

ApplyXUpdate(*args, **kw_args)
#Wrap this so that we can import it later
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.

## Fields

EMPTY_NAMESPACE = None
EMPTY_PREFIX = None
HAS_PYEXPAT = True
READ_EXTERNAL_DTD = True
XHTML_NAMESPACE = u'http://www.w3.org/1999/xhtml'
XMLNS_NAMESPACE = u'http://www.w3.org/2000/xmlns/'
XML_NAMESPACE = u'http://www.w3.org/XML/1998/namespace'