4Suite™ API Documentation

# ► Module Ft.Xml.Sax

Abstraction module for Domlette SAX usage.

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

Classes: Attributes, ContentHandler, DomBuilder, Locator, SaxPrinter |  |  |  | Globals: FEATURE_GENERATOR, FEATURE_PROCESS_XINCLUDES, PROPERTY_WHITESPACE_RULES, PROPERTY_YIELD_RESULT, XMLNS_NAMESPACE

## Classes

class Attributes
  Interface for a set of XML attributes.

      Contains a set of XML attributes, accessible by expanded name.

  ### Methods

  __contains__(self, name)
    Alias for has_key.
  __delitem__(self, name)
    Removes the attribute with the given name.
  __getitem__(self, name)
    Alias for getValue.
  __len__(self)
    Returns the number of attributes in the list.
  get(self, name, alternative=None)
    Return the value associated with attribute name; if it is not available, then return the alternative.
  getQNameByName(self, name)
    Returns the qualified name of the attribute with the given name.
  getValue(self, name)
    Returns the value of the attribute with the given name.
  has_key(self, name)
    Returns True if the attribute name is in the list, False otherwise.
  items(self)
    Return a list of (attribute_name, value) pairs.
  keys(self)
    Returns a list of the names of all attribute in the list.
  values(self)
    Return a list of all attribute values.
class ContentHandler
  Interface for receiving logical document content events.

      This is the main callback interface for the Parser. The order of
      events in this interface mirrors the order of the information in the
      document.

  ### Methods

  characters(self, content)
    Receive notification of character data.

        The parser will call this method to report each chunk of
        character data.   The parser will return all contiguous
        character data in a single chunk.

  endDocument(self)
    Receive notification of the end of a document.

        The parser will invoke this method only once, and it will
        be the last method invoked during the parse. The parser shall
        not invoke this method until it has either abandoned parsing
        (because of an unrecoverable error) or reached the end of
        input.

  endElementNS(self, (uri, localName), qualifiedName)
    Signals the end of an element.

        The uri parameter is None for elements which have no namespace,
        the qualifiedName parameter is the raw XML name used in the source
        document.

  endPrefixMapping(self, prefix)
    End the scope of a prefix-URI mapping.

        See startPrefixMapping for details. This event will always
        occur after the corresponding endElementNS event, but the order
        of endPrefixMapping events is not otherwise guaranteed.

  setDocumentLocator(self, locator)
    Called by the parser to give the application a locator for locating the origin of document events.

        The locator allows the application to determine the end
        position of any document-related event, even if the parser is
        not reporting an error. Typically, the application will use
        this information for reporting its own errors (such as
        character content that does not match an application's
        business rules). The information returned by the locator is
        probably not sufficient for use with a search engine.

        Note that the locator will return correct information only
        during the invocation of the events in this interface. The
        application should not attempt to use it at any other time.

  startDocument(self)
    Receive notification of the beginning of a document.

        The parser will invoke this method only once, before any
        other methods in this interface.

  startElementNS(self, (uri, localName), qualifiedName, atts)
    Signals the start of an element.

        The uri parameter is None for elements which have no namespace,
        the qualifiedName parameter is the raw XML name used in the source
        document, and the atts parameter holds an instance of the
        Attributes class containing the attributes of the element.

  startPrefixMapping(self, prefix, uri)
    Begin the scope of a prefix-URI Namespace mapping.

        The information from this event is not necessary for normal
        Namespace processing: the XmlParser will automatically replace
        prefixes for element and attribute names.

        There are cases, however, when applications need to use
        prefixes in character data or in attribute values, where they
        cannot safely be expanded automatically; the
        start/endPrefixMapping event supplies the information to the
        application to expand prefixes in those contexts itself, if
        necessary.

        Note that start/endPrefixMapping events are not guaranteed to
        be properly nested relative to each-other: all
        startPrefixMapping events will occur before the corresponding
        startElementNS event, and all endPrefixMapping events will occur
        after the corresponding endElementNS event, but their order is
        not guaranteed.

class DomBuilder(ContentHandler)
  A ContentHandler that is used to construct a Domlette Document.

  ### Methods

  __init__(self)
  characters(self, data)
    Overrides: characters from class ContentHandler
  endDocument(self)
    Overrides: endDocument from class ContentHandler
  endElementNS(self, expandedName, qualifiedName)
    Overrides: endElementNS from class ContentHandler
  getDocument(self)
    Returns the newly constructed Document instance.
  startDocument(self)
    Overrides: startDocument from class ContentHandler
  startElementNS(self, expandedName, qualifiedName, attributes)
    Overrides: startElementNS from class ContentHandler
  startPrefixMapping(self, prefix, uri)
    Overrides: startPrefixMapping from class ContentHandler

  ### Methods inherited from class ContentHandler

  endPrefixMapping, setDocumentLocator
class Locator
  Interface for associating a parse event with a document location. A locator object will return valid results only during calls to ContentHandler methods; at any other time, the results are unpredictable.

  ### Methods

  getColumnNumber(self)
    Return the column number where the current event ends.
  getLineNumber(self)
    Return the line number where the current event ends.
  getSystemId(self)
    Return the system identifier for the current event.
class SaxPrinter(ContentHandler)
  A ContentHandler that serializes the result using a 4Suite printer

  ### Methods

  __init__(self, printer=<Ft.Xml.Lib.XmlPrinter.XmlPrinter instance at 0xb76bcb0c>)
  characters(self, data)
    Overrides: characters from class ContentHandler
  endDocument(self)
    Overrides: endDocument from class ContentHandler
  endElementNS(self, (namespaceURI, localName), qualifiedName)
    Overrides: endElementNS from class ContentHandler
  startDocument(self)
    Overrides: startDocument from class ContentHandler
  startElementNS(self, (namespaceURI, localName), qualifiedName, attributes)
    Overrides: startElementNS from class ContentHandler
  startPrefixMapping(self, prefix, uri)
    Overrides: startPrefixMapping from class ContentHandler

  ### Methods inherited from class ContentHandler

  endPrefixMapping, setDocumentLocator

## Globals

FEATURE_GENERATOR = 'http://4suite.org/sax/features/generator'
FEATURE_PROCESS_XINCLUDES = 'http://4suite.org/sax/features/process-xincludes'
PROPERTY_WHITESPACE_RULES = 'http://4suite.org/sax/properties/whitespace-rules'
PROPERTY_YIELD_RESULT = 'http://4suite.org/sax/properties/yield-result'
XMLNS_NAMESPACE = u'http://www.w3.org/2000/xmlns/'