4Suite API Documentation: Ft.Xml.Lib.HtmlPrinter

4Suite™ API Documentation

# ► Module Ft.Xml.Lib.HtmlPrinter

This module supports document serialization in HTML syntax.

    Copyright 2005 Fourthought, Inc. (USA).
    Detailed license and copyright information: http://4suite.org/COPYRIGHT
    Project home, documentation, distributions: http://4suite.org/

Classes: HtmlPrinter |  |  |  | Globals: EMPTY_NAMESPACE

## Classes

class HtmlPrinter(Ft.Xml.Lib.XmlPrinter.XmlPrinter)
  An HtmlPrinter instance provides functions for serializing an XML or XML-like document to a stream, based on SAX-like event calls initiated by an instance of Ft.Xml.Lib.Print.PrintVisitor.

      The methods in this subclass of XmlPrinter attempt to emit a
      document conformant to the HTML 4.01 syntax, with no extra
      whitespace added for visual formatting. The degree of correctness
      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.

  ### Methods

  __init__(self, stream, encoding)
    Creates an HtmlPrinter instance.

        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.

    Overrides: __init__ from class XmlPrinter
  attribute(self, elementUri, elementName, name, value)
    Handles an attribute event.

        Extends the overridden method by writing boolean attributes in
        minimized form.

    Overrides: attribute from class XmlPrinter
  doctype(self, name, publicId, systemId)
    Handles a doctype event.

        Extends the overridden method by adding support for the case
        when there is a publicId and no systemId, which is allowed in
        HTML but not in XML.

    Overrides: doctype from class XmlPrinter
  endElement(self, namespaceUri, tagName)
    Handles an endElement event.

        Differs from the overridden method in that an end tag is not
        generated for certain elements.

    Overrides: endElement from class XmlPrinter
  processingInstruction(self, target, data)
    Handles a processingInstruction event.

        Differs from the overridden method by writing the tag with
        no "?" at the end.

    Overrides: processingInstruction from class XmlPrinter
  startDocument(self, version='4.0', standalone=None)
    Handles a startDocument event.

        Differs from the overridden method in that no XML declaration
        is written.

    Overrides: startDocument from class XmlPrinter
  startElement(self, namespaceUri, tagName, namespaces, attributes)
    Handles a startElement event.

        Extends the overridden method by disabling output escaping for
        the content of certain elements (SCRIPT and STYLE).

    Overrides: startElement from class XmlPrinter
  text(self, data, disableEscaping=0)
    Handles a text event.

        Extends the overridden method by disabling output escaping if
        in the content of certain elements like SCRIPT or STYLE.

    Overrides: text from class XmlPrinter

  ### Methods inherited from class Ft.Xml.Lib.XmlPrinter.XmlPrinter

  cdataSection, comment, endDocument, reset

  ### Members

  attrEntitiesApos = <cEntityMap>
  attrEntitiesQuot = <cEntityMap>
  booleanAttributes = {'checked': ['input'], 'compact': ['dl', 'ol', 'ul', 'dir', 'menu', 'li'], 'declare': ['object'], 'defer': ['script'], 'disabled': ['input', 'select', 'optgroup', 'option', 'textarea', 'button'], 'ismap': ['img', 'input'], 'multiple': ['select'], 'nohref': ['area'], 'noresize': ['frame'], 'noshade': ['hr'], ...}
  forbiddenEndElements = {'area': True, 'base': True, 'basefont': True, 'br': True, 'col': True, 'frame': True, 'hr': True, 'img': True, 'input': True, 'isindex': True, ...}
  noEscapeElements = {'script': True, 'style': True}
  textEntities = <cEntityMap>
  uriAttributes = {'action': ['form'], 'background': ['body'], 'cite': ['blockquote', 'del', 'ins', 'q'], 'classid': ['object'], 'codebase': ['applet', 'object'], 'data': ['object'], 'href': ['a', 'area', 'base', 'link'], 'longdesc': ['frame', 'iframe', 'img'], 'profile': ['head'], 'src': ['frame', 'iframe', 'img', 'input', 'script'], ...}

## Globals

EMPTY_NAMESPACE = None