|
OpenTop 1.3 | |||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | Cross-Platform C++ | ||||
SUMMARY: CONSTRUCTOR | METHOD | DETAIL: CONSTRUCTOR | METHOD |
#include "ot/sax/ContentHandler.h"
This is the main interface that most SAX applications implement. If the application needs to be informed of basic parsing events (such as element and character content), it implements this interface and registers an instance using XMLReader::setContentHandler().
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 sub-elements) will appear, in order, between the startElement event and the corresponding endElement event.
All the methods of ContentHandler are pure virtual which means that you must provide an implementation for each one in your derived class. This policy has been adopted to prevent subtle differences in method signatures (that would cause a new method to be declared rather than overriding the desired virtual function) from going unnoticed. However, if you find this inconvenient, you may wish to derive from DefaultHandler, which has a default implementation for all methods.
Like all SAX event handlers, a ContentHandler must be registered with a XMLReader before it can receive and process events.
RefPtr<XMLReader> rpReader = XMLReaderFactory::CreateXMLReader(); rpReader->setContentHandler(new MyContentHandler); try { rpReader->parse(url); } catch(Exception& e) { Console::Out()->println(e.toString()); }
Method Summary | |
virtual void |
characters(const CharType* pStart, size_t length)=0 Receive notification of character data. |
virtual void |
endDocument()=0 Receive notification of the end of a document. |
virtual void |
endElement(const String& namespaceURI, const String& localName, const String& qName)=0 Receive notification of the end of an element. |
virtual void |
endPrefixMapping(const String& prefix)=0 End the scope of a prefix-URI mapping. |
virtual void |
ignorableWhitespace(const CharType* pStart, size_t length)=0 Receive notification of ignorable whitespace in element content. |
virtual void |
processingInstruction(const String& target, const String& data)=0 Receive notification of a processing instruction. |
virtual void |
setDocumentLocator(Locator* pLocator)=0 Receive an object for locating the origin of SAX document events. |
virtual void |
skippedEntity(const String& name)=0 Receive notification of a skipped entity. |
virtual void |
startDocument()=0 Receive notification of the beginning of a document. |
virtual void |
startElement(const String& namespaceURI, const String& localName, const String& qName, const Attributes& atts)=0 Receive notification of the beginning of an element. |
virtual void |
startPrefixMapping(const String& prefix, const String& uri)=0 Begin the scope of a prefix-URI Namespace mapping. |
Methods inherited from class ot::ManagedObject |
addRef, getRefCount, onFinalRelease, operator=, release |
Method Detail |
virtual void characters(const CharType* pStart, size_t length)=0
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.
pStart
- length
- SAXException
- virtual void endDocument()=0
SAXException
- virtual void endElement(const String& namespaceURI, const String& localName, const String& qName)=0
For information on the names, see startElement().
namespaceURI
- localName
- qName
- SAXException
- virtual void endPrefixMapping(const String& prefix)=0
prefix
- SAXException
- virtual void ignorableWhitespace(const CharType* pStart, size_t length)=0
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().
pStart
- length
- SAXException
- virtual void processingInstruction(const String& target, const String& data)=0
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.
target
- data
- SAXException
- virtual void setDocumentLocator(Locator* pLocator)=0
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.
pLocator
- virtual void skippedEntity(const String& name)=0
name
- SAXException
- virtual void startDocument()=0
The SAX parser will invoke this method only once, before any other event callbacks (except for setDocumentLocator).
SAXException
- virtual void startElement(const String& namespaceURI, const String& localName, const String& qName, const Attributes& atts)=0
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 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).
namespaceURI
- localName
- qName
- atts
- SAXException
- virtual void startPrefixMapping(const String& prefix, const String& uri)=0
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.
prefix
- uri
- SAXException
-
|
OpenTop 1.3 | |||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | Cross-Platform C++ | ||||
SUMMARY: CONSTRUCTOR | METHOD | DETAIL: CONSTRUCTOR | METHOD |