From bd0f3345a938b35ce6a12f6150373b0955b8dd12 Mon Sep 17 00:00:00 2001 From: Timothy Pearson Date: Sun, 10 Jul 2011 15:24:15 -0500 Subject: Add Qt3 development HEAD version --- doc/html/tagreader-example.html | 159 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 159 insertions(+) create mode 100644 doc/html/tagreader-example.html (limited to 'doc/html/tagreader-example.html') diff --git a/doc/html/tagreader-example.html b/doc/html/tagreader-example.html new file mode 100644 index 0000000..0373419 --- /dev/null +++ b/doc/html/tagreader-example.html @@ -0,0 +1,159 @@ + + + + + +A tiny SAX2 parser + + + + + + + +
+ +Home + | +All Classes + | +Main Classes + | +Annotated + | +Grouped Classes + | +Functions +

A tiny SAX2 parser

+ + +

+

This example presents a small SAX2 +reader that outputs the names of all elements in an +XML document on the command line. The element names are +indented corresponding to their nesting +

This example is thoroughly explained in a +walkthrough. +


+

Header file: +

/****************************************************************************
+** $Id: qt/structureparser.h   3.3.8   edited Jan 11 14:37 $
+**
+** Copyright (C) 1992-2007 Trolltech ASA.  All rights reserved.
+**
+** This file is part of an example program for Qt.  This example
+** program may be used, distributed and modified without limitation.
+**
+*****************************************************************************/
+
+#ifndef STRUCTUREPARSER_H
+#define STRUCTUREPARSER_H
+
+#include <qxml.h>
+
+class QString;
+
+class StructureParser : public QXmlDefaultHandler
+{
+public:
+    bool startDocument();
+    bool startElement( const QString&, const QString&, const QString& ,
+                       const QXmlAttributes& );
+    bool endElement( const QString&, const QString&, const QString& );
+
+private:
+    QString indent;
+};
+
+#endif
+
+ +


+

Implementation: +

/****************************************************************************
+** $Id: qt/structureparser.cpp   3.3.8   edited Jan 11 14:37 $
+**
+** Copyright (C) 1992-2007 Trolltech ASA.  All rights reserved.
+**
+** This file is part of an example program for Qt.  This example
+** program may be used, distributed and modified without limitation.
+**
+*****************************************************************************/
+
+#include "structureparser.h"
+
+#include <stdio.h>
+#include <qstring.h>
+
+bool StructureParser::startDocument()
+{
+    indent = "";
+    return TRUE;
+}
+
+bool StructureParser::startElement( const QString&, const QString&,
+                                    const QString& qName,
+                                    const QXmlAttributes& )
+{
+    printf( "%s%s\n", (const char*)indent, (const char*)qName );
+    indent += "    ";
+    return TRUE;
+}
+
+bool StructureParser::endElement( const QString&, const QString&, const QString& )
+{
+    indent.remove( (uint)0, 4 );
+    return TRUE;
+}
+
+ +


+

Main: +

/****************************************************************************
+** $Id: qt/tagreader.cpp   3.3.8   edited Jan 11 14:37 $
+**
+** Copyright (C) 1992-2007 Trolltech ASA.  All rights reserved.
+**
+** This file is part of an example program for Qt.  This example
+** program may be used, distributed and modified without limitation.
+**
+*****************************************************************************/
+
+#include "structureparser.h"
+#include <qfile.h>
+#include <qxml.h>
+#include <qwindowdefs.h>
+
+int main( int argc, char **argv )
+{
+    if ( argc < 2 ) {
+        fprintf( stderr, "Usage: %s <xmlfile> [<xmlfile> ...]\n", argv[0] );
+        return 1;
+    }
+    StructureParser handler;
+    QXmlSimpleReader reader;
+    reader.setContentHandler( &handler );
+    for ( int i=1; i < argc; i++ ) {
+        QFile xmlFile( argv[i] );
+        QXmlInputSource source( &xmlFile );
+        reader.parse( source );
+    }
+    return 0;
+}
+
+ +

See also Qt XML Examples. + + +


+ +
Copyright © 2007 +TrolltechTrademarks +
Qt 3.3.8
+
+ -- cgit v1.2.3