Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members  

streamdom::DOMStream Class Reference

#include <sd_DOMStream.h>

Inheritance diagram for streamdom::DOMStream:

Inheritance graph
Collaboration diagram for streamdom::DOMStream:

Collaboration graph
List of all members.

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

Detailed Description

This package provides an acceptable middle ground between SAX and DOM techniques for parsing XML. A major drawback with DOM is that it requires the complete document and is very memory-intensive, yet SAX is very low-level and hard to work with.

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.


include <sd_DOMStream.h>
include <sd_SAXErrorHandler.h>
include <iostream>

using namespace streamdom;

class MyElementHandler : public DOMStream::ElementHandler
  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 ); }

code_DOMStream.h,v 1.1 2001/12/28 16:16:56 lakshman Exp

(c) V Lakshmanan,, 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.

Member Function Documentation

void streamdom::DOMStream::addElementHandler ( ElementHandler * e )

Provide a handler for DOM elements.

This element handler will be managed by DOMStream and be deleted when the DOMStream is destroyed.

void streamdom::DOMStream::addIgnoredElementHandler ( IgnoredElementHandler * e )

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.

void streamdom::DOMStream::ignoreElement ( const QString & name )

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.

The documentation for this class was generated from the following files:
Generated at Fri Jan 4 15:19:10 2002 for streamdom by doxygen1.2.8.1 written by Dimitri van Heesch, © 1997-2001