Table of Contents

Class: XMLParser ./src/peak/config/config_components.py

Wrap a SOX.NegotiatingParser for configuration-driven XML parsing

XMLParser instances use their configuration context to obtain XML element and attribute defintions, as well as default XML namespaces from properties in peak.config.xml_namespaces, and parsing functions from properties in peak.config.xml_functions (as well as from any keyword arguments supplied to the constructor).

Default namespaces allow an XML document to optionally omit XML namespace declarations. For example, this:

        [peak.config.xml_namespaces]
        pwt = "http://peak.telecommunity.com/DOMlets/"

establishes that the namespace URI for the pwt prefix will be the DOMlets namespace URI, unless the document explicitly defines otherwise. Also, if there should be a default XML namespace for the document as a whole, you can set it with the peak.config.default_xml_namespace property. Meanwhile, this:

        [peak.config.xml_functions]
        text = some_module.handleTopLevelText
        child = some_module.handleRootElement
        finish = some_module.getResult

sets up the top-level parsing functions used by the SOX.NegotiatingParser that this class uses to do the actual parsing. You can also override or supplement these top-level functions by passing keyword arguments to the XMLParser() constructor. (See peak.util.SOX.INegotiationData for info on what each parsing function is for.) Note that these functions are used only to parse the top-level document nodes, not any contained XML elements.

The behavior for the contained XML elements and attributes is determined by the XML element and attribute definitions available in the XMLParser's configuration context. These definitions must be IElementNegotiator and IAttributeNegotiator functions, as defined in peak.util.SOX. So, for example, in:

        [XML Attributes for http://peak.telecommunity.com/DOMlets/]
        domlet = pwt.negotiateDomlet
        define = pwt.negotiateDefine

the negotiateDomlet and negotiateDefine functions must implement the peak.util.sox.IAttributeNegotiator interface.

Base Classes   
Component
Methods   
__init__
makeParser
parse
parseFunctions
  __init__ 
__init__ (
        self,
        parentComponent=NOT_GIVEN,
        componentName=None,
        **kw,
        )

  makeParser 
makeParser ( self )

Return a configured NegotiatingParser

  parse 
parse ( self,  source )

Parse a stream source using the configured parser

source should be a stream source (see config.getStreamFactory()) for the XML to be parsed. Note that this method will only return a value if a finish function is defined for the top-level document. The finish function can be set as a peak.config.xml_functions property, passed in via a keyword argument to the constructor, or it can be set by a start function.

  parseFunctions 
parseFunctions ( self )

Return top-level parse function map based on kwargs and props


Table of Contents

This document was automatically generated on Mon Apr 29 01:11:05 2024 by HappyDoc version 2.1