Unicorn XML Toolkit
Version 1.50.00

Namespace Sax
Class CContentHandler

class CContentHandler: virtual public CInterface {
public:
    CContentHandler();
    virtual ~CContentHandler();
public:
    virtual void SetDocumentLocator(CLocator *pLocator) = 0;
    virtual void StartDocument() = 0;
    virtual void EndDocument() = 0;
    virtual void StartPrefixMapping(
        const WCHAR *pszPrefix,
        const WCHAR *pszUri) = 0;
    virtual void EndPrefixMapping(const WCHAR *pszPrefix) = 0;
    virtual void StartElement(
        const WCHAR *pszUri,
        const WCHAR *pszLocalName,
        const WCHAR *pszQName,
        CAttributes *pAtts) = 0;
    virtual void EndElement(
        const WCHAR *pszUri,
        const WCHAR *pszLocalName,
        const WCHAR *pszQName) = 0;
    virtual void Characters(
        const WCHAR *pCh, int nLength) = 0;
    virtual void IgnorableWhitespace(
        const WCHAR *pCh, int nLength) = 0;
    virtual void ProcessingInstruction(
        const WCHAR *pszTarget,
        const WCHAR *pszData) = 0;
    virtual void SkippedEntity(const WCHAR *pszName) = 0;
    };
typedef XInterface<CContentHandler> XContentHandler;

The interface for receiving notification of the logical content of a document.

This is the main interface that most SAX applications implement: if the application needs to be informed of basic parsing events, it implements this interface and registers an instance with the SAX reader using the CXmlReader::SetContentHandler method. The reader uses the instance to report basic document-related events like the start and end of elements and character data.

The order of events in this interface is very important, and mirrors the order of information in the document itself. For example, all of an element's content (character data, processing instructions, and/or subelements) will appear, in order, between the StartElement event and the corresponding EndElement event.

Since:
1.00.00
Version:
1.50.00
Author:
C++ interfaces by Alexey Gokhberg; based on the original SAX2 specification by David Megginson
See Also:
CAttributes, CLocator
Constructor/Destructor Summary
CContentHandler ();
����������Constructs the content handler.
~CContentHandler ();
����������Destroys the content handler.

Function Summary
void SetDocumentLocator (CLocator *pLocator);
����������Receives an object for locating the origin of SAX document events.
void StartDocument ();
����������Receives notification of the beginning of a document.
void EndDocument ();
����������Receives notification of the end of a document.
void StartPrefixMapping (const WCHAR *pszPrefix, const WCHAR *pszUri);
����������Begins the scope of a prefix-URI namespace mapping.
void EndPrefixMapping (const WCHAR *pszPrefix);
����������Ends the scope of a prefix-URI mapping.
void StartElement (const WCHAR *pszUri, const WCHAR *pszLocalName, const WCHAR *pszQName, CAttributes *pAtts);
����������Receives notification of the beginning of an element.
void EndElement (const WCHAR *pszUri, const WCHAR *pszLocalName, const WCHAR *pszQName);
����������Receives notification of the end of an element.
void Characters (const WCHAR *pCh, int nLength);
����������Receives notification of character data.
void IgnorableWhitespace (const WCHAR *pCh, int nLength);
����������Receives notification of ignorable whitespace in element content.
void ProcessingInstruction (const WCHAR *pszTarget, const WCHAR *pszData);
����������Receives notification of a processing instruction.
void SkippedEntity (const WCHAR *pszName);
����������Receives notification of a skipped entity.

Constructor/Destructor Detail

CContentHandler

CContentHandler();

Constructs the content handler.

~CContentHandler

virtual ~CContentHandler();

Destroys the content handler.

Function Detail

SetDocumentLocator

virtual void SetDocumentLocator(CLocator *pLocator) = 0;

Receives an object for locating the origin of SAX document events.

A SAX reader is strongly encouraged (though not absolutely required) to supply a locator: if it does so, it must supply the locator to the application by invoking this method before invoking any of the other methods in the CContentHandler class.

The locator allows the application to determine the end position of any document-related event, even if the reader 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.

Parameters:
pLocator - the object that can return the location of any SAX document event

StartDocument

virtual void StartDocument() = 0;

Receives notification of the beginning of a document.

The SAX reader will invoke this method only once, before any other methods in this interface or in CDtdHandler (except for SetDocumentLocator ).

EndDocument

virtual void EndDocument() = 0;

Receives notification of the end of a document.

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

StartPrefixMapping

virtual void StartPrefixMapping(
    const WCHAR *pszPrefix,
    const WCHAR *pszUri) = 0;

Begins 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 should never be Start/EndPrefixMapping events for the "xml" prefix, since it is predeclared and immutable.

Parameters:
pszPrefix - the namespace prefix being declared
pszUri - the namespace URI the prefix is mapped to

EndPrefixMapping

virtual void EndPrefixMapping(const WCHAR *pszPrefix) = 0;

Ends 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:
pszPrefix - the prefix that was being mapped

StartElement

virtual void StartElement(
    const WCHAR *pszUri,
    const WCHAR *pszLocalName,
    const WCHAR *pszQName,
    CAttributes *pAtts) = 0;

Receives notification of the beginning of an element.

The reader 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:

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 properties:

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 property is true (it is false by default, and support for a true value is optional).

Parameters:
pszUri - the namespace URI, or the empty string if the element has no namespace URI or if namespace processing is not being performed
pszLocalName - the local name (without prefix), or the empty string if namespace processing is not being performed
pszQName - the qualified name (with prefix), or the empty string if qualified names are not available
pAtts - the list of attributes attached to the element; if there are no attributes, it shall be an empty attribute list

EndElement

virtual void EndElement(
    const WCHAR *pszUri,
    const WCHAR *pszLocalName,
    const WCHAR *pszQName) = 0;

Receives notification of the end of an element.

The SAX reader 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:
pszUri - the namespace URI, or the empty string if the element has no namespace URI or if namespace processing is not being performed
pszLocalName - the local name (without prefix), or the empty string if namespace processing is not being performed
pszQName - the qualified name (with prefix), or the empty string if qualified names are not available

Characters

virtual void Characters(
    const WCHAR *pCh, int nLength) = 0;

Receives notification of character data.

The reader will call this method to report each chunk of character data. SAX readers 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 application must not attempt to read from the array outside of the specified range.

Note that some readers will report whitespace in element content using the IgnorableWhitespace method rather than this one (readers which implement validating parsers must do so).

Parameters:
pCh - the array of characters from the XML document
nLength - the number of characters to read from the array

IgnorableWhitespace

virtual void IgnorableWhitespace(
    const WCHAR *pCh, int nLength) = 0;

Receives notification of ignorable whitespace in element content.

Readers which implement validating parsers must use this method to report each chunk of whitespace in element content (see the W3C XML 1.0 recommendation, section 2.10); readers implementing non-validating parsers may also use this method if they are capable of parsing and using content models.

SAX readers 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 application must not attempt to read from the array outside of the specified range.

Parameters:
pCh - the array of characters from the XML document
nLength - the number of characters to read from the array

ProcessingInstruction

virtual void ProcessingInstruction(
    const WCHAR *pszTarget,
    const WCHAR *pszData) = 0;

Receives notification of a processing instruction.

The reader will invoke this method once for each processing instruction found: note that processing instructions may occur before or after the main document element.

A SAX reader must never 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:
pszTarget - the processing instruction target
pszData - the processing instruction data, or the empty string if none was supplied; does not include any whitespace separating it from the target

SkippedEntity

virtual void SkippedEntity(const WCHAR *pszName) = 0;

Receives notification of a skipped entity.

The reader 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 properties.

Parameters:
pszName - 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]" .

Unicorn XML Toolkit
Version 1.50.00


This document was created using Unicorn DOC++.

Copyright 1999-2001 Unicorn Enterprises SA.
All Rights Reserved.