4Suite™ API Documentation

# ► Module Ft.Xml.Lib.Print

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

Classes: PrintVisitor |  |  |  | Functions: PrettyPrint, Print |  |  |  | Fields: XMLNS_NAMESPACE, XML_NAMESPACE

## Classes

class PrintVisitor
Provides functions to recursively walk a DOM or Domlette object and generate SAX-like event calls for each node encountered. See the printer classes (XMLPrinter, HTMLPrinter, etc.) for the event handlers.

### Methods

__init__(self, stream, encoding, nsHints=None, isHtml=False, indent=False)
Initializes an instance of the class, selecting the appropriate printer to use, depending on the isHtml and indent flags. nsHints, if given, is a dictionary of namespace mappings that help determine if namespace declarations need to be emitted when visiting the first Element node.
visit(self, node)
Starts walking the tree at the given node.
visitAttribute(self, node)
Called when an Attribute node is encountered. Generates an attribute event for the printer.
visitCDATASection(self, node)
Called when a CDATASection node is encountered. Generates a cdataSection event for the printer.
visitComment(self, node)
Called when a Comment node is encountered. Generates a comment event for the printer.
visitDocument(self, node)
Called when a Document node is encountered. Just proceeds to the associated DocumentType node, if any, and then to the node's children.
visitDocumentFragment(self, node)
Called when a DocumentFragment node is encountered. Just proceeds to the node's children.
visitDocumentType(self, node)
Called when a DocumentType node is encountered. Generates a doctype event for the printer.
visitElement(self, node)
Called when an Element node is encountered. Generates for the printer a startElement event, events for the node's children (including attributes), and an endElement event.
visitNotImplemented(self, node)
Called when an known but unsupported type of node is encountered, always raising a NotImplementedError exception. The unsupported node types are those that require DTD subset support: entity nodes, entity reference nodes, and notation nodes.
visitProcessingInstruction(self, node)
Called when a ProcessingInstruction node is encountered. Generates a processingInstruction event for the printer.
visitText(self, node)
Called when a Text node is encountered. Generates a text event for the printer.

## Functions

PrettyPrint(root, stream=<open file '<stdout>', mode 'w' at 0x8130068>, encoding='UTF-8', asHtml=None)
Given a Node instance assumed to be the root of a DOM or Domlette tree, this function serializes the document to the given stream or stdout, using the given encoding (UTF-8 is the default). Extra whitespace is added to the output for visual formatting. The asHtml flag can be used to force HTML-style serialization of an XML DOM. Otherwise, the DOM type (HTML or XML) is automatically determined. This function does nothing if root is not a Node.
It is preferable that users import this from Ft.Xml.Domlette
rather than directly from Ft.Xml.Lib.Print.
Print(root, stream=<open file '<stdout>', mode 'w' at 0x8130068>, encoding='UTF-8', asHtml=None)
Given a Node instance assumed to be the root of a DOM or Domlette tree, this function serializes the document to the given stream or stdout, using the given encoding (UTF-8 is the default). The asHtml flag can be used to force HTML-style serialization of an XML DOM. Otherwise, the DOM type (HTML or XML) is automatically determined. This function does nothing if root is not a Node.
It is preferable that users import this from Ft.Xml.Domlette
rather than directly from Ft.Xml.Lib.Print.

## Fields

XMLNS_NAMESPACE = u'http://www.w3.org/2000/xmlns/'
XML_NAMESPACE = u'http://www.w3.org/XML/1998/namespace'