#include <sd_DOMStream.h>
Inheritance diagram for streamdom::DOMStream:
Public Methods | |
virtual bool | startElement (const QString &namespaceURI, const QString &localName, const QString &qName, const QXmlAttributes &atts) |
virtual bool | endElement (const QString &namespaceURI, const QString &localName, const QString &qName) |
virtual bool | characters (const QString &ch) |
virtual | ~DOMStream () |
void | ignoreElement (const QString &name) |
void | addElementHandler (ElementHandler *e) |
void | removeElementHandler (ElementHandler *e) |
void | addIgnoredElementHandler (IgnoredElementHandler *e) |
void | removeIgnoredElementHandler (IgnoredElementHandler *e) |
DOMStream () | |
virtual void | setDocumentLocator (QXmlLocator *locator) |
virtual bool | startDocument () |
virtual bool | endDocument () |
virtual bool | startPrefixMapping (const QString &prefix, const QString &uri) |
virtual bool | endPrefixMapping (const QString &prefix) |
virtual bool | ignorableWhitespace (const QString &ch) |
virtual bool | processingInstruction (const QString &target, const QString &data) |
virtual bool | skippedEntity (const QString &name) |
virtual QString | errorString () |
This package converts SAX events from the SAXParser to which it is attached into events for one or more DOM Element handlers provided. These handlers receive DOM elements and can therefore process DOM nodes even if the entire document is not available.
This package processes elements efficiently memory-wise, by hanging on only to incomplete elements.
Usage:
include <sd_DOMStream.h> include <sd_SAXErrorHandler.h> include <iostream> using namespace streamdom; class MyElementHandler : public DOMStream::ElementHandler { public: virtual ~MyElementHandler() { } virtual void handleElement( const QDomElement& e ) { std::cout << "Element " << e.nodeName() << ": " << e.text() << "
"; } } ; int main(int argc, char* argv[]) { if ( argc != 2 ){ std::cerr << "Usage: " << argv[0] << " filename
"; return -1; } DOMStream streamer; SAXErrorHandler logger; streamer.ignoreElement("codeindex"); // or whatever streamer.addElementHandler( new MyElementHandler() ); QFile fp(argv[1]); QXmlSimpleReader parser; parser.setContentHandler( &streamer ); parser.setErrorHandler( &logger ); parser.parse( fp ); }
(c) V Lakshmanan, http://www.vlakshman.com/, Dec. 2001
Permission is granted to use/modify this class freely in any software -- commercial, open-source or proprietary -- under the condition that this documentation, copyright and usage information may not be removed.
This software is supplied in the hope that it will be useful. There is no warranty whatsoever, not even any implied warranties.
|
Provide a handler for DOM elements. This element handler will be managed by DOMStream and be deleted when the DOMStream is destroyed. |
|
Provide a handler for DOM elements that have been ignored. This element handler will be managed by DOMStream and be deleted when the DOMStream is destroyed. |
|
Mark elements you don't wish to be notified about. This is a convenient way to avoid memory usage and DOM-tree building for elements that are of no concern. Note that child elements of the element to be ignored will still be built and notified about. This behavior is especially useful for the element that may enclose an entire document. |