Cross-Platform C++

ot::sax
class DefaultHandler

#include "ot/sax/DefaultHandler.h"

ot::sax::ContentHandler ot::sax::DTDHandler ot::sax::EntityResolver ot::sax::ErrorHandler ot::ManagedObject ot::ManagedObject ot::ManagedObject ot::ManagedObject Default base class for SAX2 event handlers.

This class is available as a convenience base class for SAX2 applications: it provides default implementations for all of the callbacks in the four core SAX2 handler classes:

Application writers can extend this class when they need to implement only part of an interface; parser writers can instantiate this class to provide default handlers when the application has not supplied its own.




Method Summary
 virtual void characters(const CharType* pStart, size_t length)
         Receive notification of character data.
 virtual void endDocument()
         Receive notification of the end of a document.
 virtual void endElement(const String& namespaceURI, const String& localName, const String& qName)
         Receive notification of the end of an element.
 virtual void endPrefixMapping(const String& prefix)
         End the scope of a prefix-URI mapping.
 virtual void error(const SAXParseException& exception)
         Receive notification of a recoverable error.
 virtual void fatalError(const SAXParseException& exception)
         Receive notification of a non-recoverable error.
 virtual void ignorableWhitespace(const CharType* pStart, size_t length)
         Receive notification of ignorable whitespace in element content.
 virtual void notationDecl(const String& name, const String& publicId, const String& systemId)
         Receive notification of a notation declaration event.
 virtual void processingInstruction(const String& target, const String& data)
         Receive notification of a processing instruction.
 virtual RefPtr< InputSource > resolveEntity(const String& publicId, const String& systemId)
         Allow the application to resolve external entities.
 virtual void setDocumentLocator(Locator* pLocator)
         Receive an object for locating the origin of SAX document events.
 virtual void skippedEntity(const String& name)
         Receive notification of a skipped entity.
 virtual void startDocument()
         Receive notification of the beginning of a document.
 virtual void startElement(const String& namespaceURI, const String& localName, const String& qName, const Attributes& atts)
         Receive notification of the beginning of an element.
 virtual void startPrefixMapping(const String& prefix, const String& uri)
         Begin the scope of a prefix-URI Namespace mapping.
 virtual void unparsedEntityDecl(const String& name, const String& publicId, const String& systemId, const String& notationName)
         Receive notification of an unparsed entity declaration event.
 virtual void warning(const SAXParseException& exception)
         Receive notification of a warning.

Methods inherited from class ot::ManagedObject
addRef, getRefCount, onFinalRelease, operator=, release

Method Detail

characters

virtual void characters(const CharType* pStart,
                        size_t length)
Receive notification of character data. The Parser will call this method to report each chunk of character data. SAX parsers may return all contiguous character data in a single chunk, or they may split it into several chunks; however, all of the characters in any single event must come from the same external entity so that the Locator provides useful information.

The array of characters will form an integral number of Unicode characters in the internal OpenTop encoding.

The memory for the character array is managed by the SAX parser and the pStart pointer is only valid for the scope of this function. The application must not attempt to read from the array beyond the specified length.

Note that when the SAX parser has an element content model available (i.e. it has read a declaration for the current element from a DTD) it will report whitespace in element content using the ignorableWhitespace() event.

Parameters:
pStart - The start of an array of CharType characters from the XML document.
length - The number of CharType characters in the array.
Exceptions:
SAXException - The client may throw an exception during processing. If so, the SAX XML parser will stop parsing the current document.
See also:
ignorableWhitespace() , Locator

endDocument

virtual void endDocument()
Receive notification of the end of a document. The SAX 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.

Exceptions:
SAXException - The client may throw an exception during processing. If so, the SAX XML parser will stop parsing the current document.
See also:
startDocument()

endElement

virtual void endElement(const String& namespaceURI,
                        const String& localName,
                        const String& qName)
Receive notification of the end of an element. The SAX parser will invoke this method at the end of every element in the XML document; there will be a corresponding startElement() event for every endElement event (even when the element is empty).

For information on the names, see startElement().

Parameters:
namespaceURI - The Namespace URI, or the empty string if the element has no Namespace URI or if Namespace processing is not being performed.
localName - The local name (without prefix), or the empty string if Namespace processing is not being performed.
qName - The qualified XML 1.0 name (with prefix), or the empty string if qualified names are not available.
Exceptions:
SAXException - The client may throw an exception during processing. If so, the SAX XML parser will stop parsing the current document.
See also:
startElement()

endPrefixMapping

virtual void endPrefixMapping(const String& prefix)
End the scope of a prefix-URI mapping. See startPrefixMapping() for details. This event will always occur after the corresponding endElement() event, but the order of endPrefixMapping() events is not otherwise guaranteed.

Parameters:
prefix - The namespace prefix.
Exceptions:
SAXException - The client may throw an exception during processing. If so, the SAX XML parser will stop parsing the current document.
See also:
startPrefixMapping() , endElement()

error

virtual void error(const SAXParseException& exception)
Receive notification of a recoverable error.

This corresponds to the definition of "error" in section 1.2 of the W3C XML 1.0 Recommendation. For example, a validating parser would use this callback to report the violation of a validity constraint. The default behaviour is to take no action.

The SAX parser must continue to provide normal parsing events after invoking this method: it should still be possible for the application to process the document through to the end. If the application cannot do so, then the parser should report a fatal error even if the XML 1.0 recommendation does not require it to do so.

Filters may use this method to report other, non-XML errors as well.

Parameters:
exception - The error information encapsulated in a SAXParseException.
Exceptions:
SAXException - The application may throw an exception during processing. If so, the SAX XML parser will stop parsing the current document.

fatalError

virtual void fatalError(const SAXParseException& exception)
Receive notification of a non-recoverable error.

This corresponds to the definition of "fatal error" in section 1.2 of the W3C XML 1.0 Recommendation. For example, a parser would use this callback to report the violation of a well-formedness constraint.

The application must assume that the document is unusable after the parser has invoked this method, and should continue (if at all) only for the sake of collecting additional error messages.

The default implementation throws the exception parameter as an exception.

Parameters:
exception - The error information encapsulated in a SAXParseException.
Exceptions:
SAXException - The application may throw an exception during processing. If so, the SAX XML parser will stop parsing the current document.

ignorableWhitespace

virtual void ignorableWhitespace(const CharType* pStart,
                                 size_t length)
Receive notification of ignorable whitespace in element content. When the SAX Parser has a content model for the current element, it will use this method to report each chunk of whitespace in element content (see the W3C XML 1.0 recommendation, section 2.10).

SAX parsers may return all contiguous whitespace in a single chunk, or they may split it into several chunks; however, all of the characters in any single event must come from the same external entity, so that the Locator provides useful information.

The array of characters will form an integral number of Unicode characters in the internal OpenTop encoding.

The memory for the character array is managed by the SAX parser and the pStart pointer is only valid for the scope of this function. The application must not attempt to read from the array beyond the specified length.

Note that, when validating, the SAX parser will report whitespace in element content using the ignorableWhitespace().

Parameters:
pStart - The start of an array of CharType characters from the XML document.
length - The number of CharType characters in the array.
Exceptions:
SAXException - The client may throw an exception during processing. If so, the SAX XML parser will stop parsing the current document.
See also:
characters()

notationDecl

virtual void notationDecl(const String& name,
                          const String& publicId,
                          const String& systemId)
Receive notification of a notation declaration event.

It is up to the application to record the notation for later reference, if necessary.

At least one of publicId and systemId must be present. If a system identifier is present, and it is a URL, it will be fully resolved if the http://elcel.com/opentop/sax/features/resolve-entity-uris feature is set to true (the default).

There is no guarantee that the notation declaration will be reported before any unparsed entities that use it.

Parameters:
name - The notation name.
publicId - The notation's public identifier, or the empty string if none was given.
systemId - The notation's system identifier, or the empty string if none was given.
Exceptions:
SAXException - The application may throw an exception during processing. If so, the SAX XML parser will stop parsing the current document.
See also:
unparsedEntityDecl() , Attributes

processingInstruction

virtual void processingInstruction(const String& target,
                                   const String& data)
Receive notification of a processing instruction. The Parser will invoke this method once for each processing instruction found: note that processing instructions may occur before or after the main document element.

The SAX parser will not report an XML declaration (XML 1.0, section 2.8) or a text declaration (XML 1.0, section 4.3.1) using this method.

Parameters:
target - The processing instruction target.
data - The processing instruction data, or the empty string if none was supplied. The data does not include any whitespace separating it from the target.
Exceptions:
SAXException - The client may throw an exception during processing. If so, the SAX XML parser will stop parsing the current document.

resolveEntity

virtual RefPtr< InputSourceresolveEntity(const String& publicId,
                                            const String& systemId)
Allow the application to resolve external entities.

The Parser will call this method before opening any external entity except the top-level document entity (including the external DTD subset, external entities referenced within the DTD, and external entities referenced within the document element): the application may request that the parser resolve the entity itself, that it use an alternative URI, or that it use an entirely different input source.

Application writers can use this method to redirect external system identifiers to secure and/or local URIs, to look up public identifiers in a catalogue, or to read an entity from a database or other input source (including, for example, a dialog box).

If the system identifier is a URL, it will be fully resolved if the http://elcel.com/opentop/sax/features/resolve-entity-uris feature is set to true (the default).

Parameters:
publicId - The public identifier of the external entity being referenced, or the empty string if none was supplied.
systemId - The system identifier of the external entity being referenced.
Returns:
An InputSource object describing the new input source, or a null pointer to request that the parser open a regular URL connection to the system identifier.
Exceptions:
SAXException - The client may throw an exception during processing. If so, the SAX XML parser will stop parsing the current document.
See also:
InputSource

setDocumentLocator

virtual void setDocumentLocator(Locator* pLocator)
Receive an object for locating the origin of SAX document events. The SAX parser supplies the Locator to the application by invoking this method before invoking any of the other methods in the ContentHandler interface. The application should store pLocator in a RefPtr<Locator> if it wishes to use it in the future.

    void myHandler::setDocumentLocator(Locator* pLocator)
    {
        m_rpLocator = pLocator;
    }

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).

    void myHandler::ignorableWhitespace(const String& string)
    {
        Console::cout() << OT_T("received ignorable whitespace at [")
                        << m_rpLocator->getLineNumber()
                        << OT_T(",")
                        << m_rpLocator->getColumnNumber()
                        << OT_T("]") << endl;
    }

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.

Parameters:
pLocator - A pointer to an object that can return the location of any SAX document event.
See also:
Locator

skippedEntity

virtual void skippedEntity(const String& name)
Receive notification of a skipped entity. The Parser will invoke this method once for each entity skipped. Non-validating processors may skip entities if they have not seen the declarations (because, for example, the entity was declared in an external DTD subset). All processors may skip external entities, depending on the values of the http://xml.org/sax/features/external-general-entities and the http://xml.org/sax/features/external-parameter-entities features.

Parameters:
name - The name of the skipped entity. If it is a parameter entity, the name will begin with '%', and if it is the external DTD subset, it will be the string "[dtd]".
Exceptions:
SAXException - The client may throw an exception during processing. If so, the SAX XML parser will stop parsing the current document.

startDocument

virtual void startDocument()
Receive notification of the beginning of a document.

The SAX parser will invoke this method only once, before any other event callbacks (except for setDocumentLocator).

Exceptions:
SAXException - The client may throw an exception during processing. If so, the SAX XML parser will stop parsing the current document.
See also:
endDocument()

startElement

virtual void startElement(const String& namespaceURI,
                          const String& localName,
                          const String& qName,
                          const Attributes& atts)
Receive notification of the beginning of an element. The Parser will invoke this method at the beginning of every element in the XML document; there will be a corresponding endElement() event for every startElement event (even when the element is empty). All of the element's content will be reported, in order, before the corresponding endElement event.

This event allows up to three name components for each element:

  1. the Namespace URI;
  2. the local name; and
  3. the qualified (prefixed) name.

Any or all of these may be provided, depending on the values of the http://xml.org/sax/features/namespaces and the http://xml.org/sax/features/namespace-prefixes features:

Note that the attribute list provided will contain only attributes with explicit values (specified or defaulted): #IMPLIED attributes will be omitted. The attribute list will contain attributes used for Namespace declarations (xmlns* attributes) only if the http://xml.org/sax/features/namespace-prefixes feature is true (it is false by default).

Parameters:
namespaceURI - The Namespace URI, or the empty string if the element has no Namespace URI or if Namespace processing is not being performed.
localName - The local name (without prefix), or the empty string if Namespace processing is not being performed.
qName - The qualified name (with prefix).
atts - The attributes attached to the element. If there are no attributes, it shall be an empty Attributes object.
Exceptions:
SAXException - The client may throw an exception during processing. If so, the SAX XML parser will stop parsing the current document.
See also:
endElement() , Attributes

startPrefixMapping

virtual void startPrefixMapping(const String& prefix,
                                const String& uri)
Begin the scope of a prefix-URI Namespace mapping. The information from this event is not necessary for normal Namespace processing: the SAX XML reader will automatically replace prefixes for element and attribute names when the http://xml.org/sax/features/namespaces feature is true (the default).

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 startElement() event, and all endPrefixMapping() events will occur after the corresponding endElement() event, but their order is not otherwise guaranteed.

There will never be start/endPrefixMapping events for the 'xml' prefix, since it is predeclared and immutable.

Parameters:
prefix - The Namespace prefix being declared.
uri - The Namespace URI the prefix is mapped to.
Exceptions:
SAXException - The client may throw an exception during processing. If so, the SAX XML parser will stop parsing the current document.
See also:
endPrefixMapping , startElement

unparsedEntityDecl

virtual void unparsedEntityDecl(const String& name,
                                const String& publicId,
                                const String& systemId,
                                const String& notationName)
Receive notification of an unparsed entity declaration event.

Note that the notation name corresponds to a notation reported by the notationDecl() event. It is up to the application to record the entity for later reference, if necessary.

If the system identifier is a URL, it will be fully resolved if the http://elcel.com/opentop/sax/features/resolve-entity-uris feature is set to true (the default).

Parameters:
name - The unparsed entity's name.
publicId - The entity's public identifier, or the empty string if none was given.
systemId - The entity's system identifier.
notationName - The name of the associated notation.
Exceptions:
SAXException - The application may throw an exception during processing. If so, the SAX XML parser will stop parsing the current document.
See also:
notationDecl() , Attributes

warning

virtual void warning(const SAXParseException& exception)
Receive notification of a warning.

SAX parsers will use this method to report conditions that are not errors or fatal errors as defined by the XML 1.0 recommendation. The default behaviour is to take no action.

The SAX parser must continue to provide normal parsing events after invoking this method: it should still be possible for the application to process the document through to the end.

Filters may use this method to report other, non-XML warnings as well.

Parameters:
exception - The warning information encapsulated in a SAXParseException.
Exceptions:
SAXException - The application may throw an exception during processing. If so, the SAX XML parser will stop parsing the current document.


Cross-Platform C++

Found a bug or missing feature? Please email us at support@elcel.com

Copyright © 2000-2003 ElCel Technology   Trademark Acknowledgements