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-with-features-example.html | 229 ++++++++++++++++++++++++++ 1 file changed, 229 insertions(+) create mode 100644 doc/html/tagreader-with-features-example.html (limited to 'doc/html/tagreader-with-features-example.html') diff --git a/doc/html/tagreader-with-features-example.html b/doc/html/tagreader-with-features-example.html new file mode 100644 index 0000000..0221f03 --- /dev/null +++ b/doc/html/tagreader-with-features-example.html @@ -0,0 +1,229 @@ + + + + + +Demonstration of SAX2 features + + + + + + + +
+ +Home + | +All Classes + | +Main Classes + | +Annotated + | +Grouped Classes + | +Functions +

Demonstration of SAX2 features

+ + +

+

This example presents a small SAX2 +reader that outputs the qualified names and the +respective namespace URIs of all elements and attributes in an +XML file. Additionally the tree structure of the document is displayed. +

In three listviews the program shows the different output of the reader +depending on how the SAX2 features +http://xml.org/sax/features/namespaces and +http://xml.org/sax/features/namespace-prefixes are set. +

This example is thoroughly explained in a +walkthrough. +


+

Header file: +

/*
+$Id: qt/structureparser.h   3.3.8   edited May 27 2003 $
+*/
+
+#ifndef STRUCTUREPARSER_H
+#define STRUCTUREPARSER_H
+
+#include <qxml.h>
+#include <qptrstack.h>
+
+class QListView;
+class QListViewItem;
+class QString;
+
+class StructureParser: public QXmlDefaultHandler
+{
+public:
+    StructureParser( QListView * );
+    bool startElement( const QString&, const QString&, const QString& ,
+                       const QXmlAttributes& );
+    bool endElement( const QString&, const QString&, const QString& );
+
+    void setListView( QListView * );
+
+private:
+    QPtrStack<QListViewItem> stack;
+    QListView * table;
+};
+
+#endif
+
+ +


+

Implementation: +

/*
+$Id: qt/structureparser.cpp   3.3.8   edited May 27 2003 $
+*/
+
+#include "structureparser.h"
+
+#include <qstring.h>
+#include <qlistview.h>
+
+StructureParser::StructureParser( QListView * t )
+                : QXmlDefaultHandler()
+{
+    setListView( t );
+}
+
+void StructureParser::setListView( QListView * t )
+{
+    table = t;
+    table->setSorting( -1 );
+    table->addColumn( "Qualified name" );
+    table->addColumn( "Namespace" );
+}
+
+bool StructureParser::startElement( const QString& namespaceURI,
+                                    const QString& ,
+                                    const QString& qName,
+                                    const QXmlAttributes& attributes)
+{
+    QListViewItem * element;
+
+    if ( ! stack.isEmpty() ){
+        QListViewItem *lastChild = stack.top()->firstChild();
+        if ( lastChild ) {
+            while ( lastChild->nextSibling() )
+                lastChild = lastChild->nextSibling();
+        }
+        element = new QListViewItem( stack.top(), lastChild, qName, namespaceURI );
+    } else {
+        element = new QListViewItem( table, qName, namespaceURI );
+    }
+    stack.push( element );
+    element->setOpen( TRUE );
+
+    if ( attributes.length() > 0 ) {
+        for ( int i = 0 ; i < attributes.length(); i++ ) {
+            new QListViewItem( element, attributes.qName(i), attributes.uri(i) );
+        }
+    }
+    return TRUE;
+}
+
+bool StructureParser::endElement( const QString&, const QString&,
+                                  const QString& )
+{
+    stack.pop();
+    return TRUE;
+}
+
+ +


+

Main: +

/****************************************************************************
+** $Id: qt/tagreader.cpp   3.3.8   edited Jan 11 14:46 $
+**
+** Copyright (C) 2005-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 <qapplication.h>
+#include <qfile.h>
+#include <qxml.h>
+#include <qlistview.h>
+#include <qgrid.h>
+#include <qmainwindow.h>
+#include <qlabel.h>
+
+int main( int argc, char **argv )
+{
+    QApplication app( argc, argv );
+
+    QFile xmlFile( argc == 2 ? argv[1] : "fnord.xml" );
+    QXmlInputSource source( &xmlFile );
+
+    QXmlSimpleReader reader;
+
+    QGrid * container = new QGrid( 3 );
+
+    QListView * nameSpace = new QListView( container, "table_namespace" );
+    StructureParser * handler = new StructureParser( nameSpace );
+    reader.setContentHandler( handler );
+    reader.parse( source );
+
+    QListView * namespacePrefix = new QListView( container,
+                                                 "table_namespace_prefix" );
+    handler->setListView( namespacePrefix );
+    reader.setFeature( "http://xml.org/sax/features/namespace-prefixes",
+                       TRUE );
+    source.reset();
+    reader.parse( source );
+
+    QListView * prefix = new QListView( container, "table_prefix");
+    handler->setListView( prefix );
+    reader.setFeature( "http://xml.org/sax/features/namespaces", FALSE );
+    source.reset();
+    reader.parse( source );
+
+    // namespace label
+    (void) new QLabel(
+             "Default:\n"
+             "http://xml.org/sax/features/namespaces: TRUE\n"
+             "http://xml.org/sax/features/namespace-prefixes: FALSE\n",
+             container );
+
+    // namespace prefix label
+    (void) new QLabel(
+             "\n"
+             "http://xml.org/sax/features/namespaces: TRUE\n"
+             "http://xml.org/sax/features/namespace-prefixes: TRUE\n",
+             container );
+
+    // prefix label
+    (void) new QLabel(
+             "\n"
+             "http://xml.org/sax/features/namespaces: FALSE\n"
+             "http://xml.org/sax/features/namespace-prefixes: TRUE\n",
+             container );
+
+
+    app.setMainWidget( container );
+    container->show();
+    return app.exec();
+}
+
+ +

See also Qt XML Examples. + + +


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