summaryrefslogtreecommitdiffstats
path: root/examples/xml/tagreader-with-features
diff options
context:
space:
mode:
Diffstat (limited to 'examples/xml/tagreader-with-features')
-rw-r--r--examples/xml/tagreader-with-features/fnord.xml13
-rw-r--r--examples/xml/tagreader-with-features/structureparser.cpp56
-rw-r--r--examples/xml/tagreader-with-features/structureparser.h29
-rw-r--r--examples/xml/tagreader-with-features/tagreader-with-features.pro11
-rw-r--r--examples/xml/tagreader-with-features/tagreader.cpp74
-rw-r--r--examples/xml/tagreader-with-features/tagreader.doc40
6 files changed, 223 insertions, 0 deletions
diff --git a/examples/xml/tagreader-with-features/fnord.xml b/examples/xml/tagreader-with-features/fnord.xml
new file mode 100644
index 0000000..4d1303d
--- /dev/null
+++ b/examples/xml/tagreader-with-features/fnord.xml
@@ -0,0 +1,13 @@
+<document xmlns:book = 'http://trolltech.com/fnord/book/'
+ xmlns = 'http://trolltech.com/fnord/' >
+<book>
+ <book:title>Practical XML</book:title>
+ <book:author xmlns:fnord = 'http://trolltech.com/fnord/'
+ title="Ms"
+ fnord:title="Goddess"
+ name="Eris Kallisti"/>
+ <chapter>
+ <title>A Namespace Called fnord</title>
+ </chapter>
+</book>
+</document>
diff --git a/examples/xml/tagreader-with-features/structureparser.cpp b/examples/xml/tagreader-with-features/structureparser.cpp
new file mode 100644
index 0000000..ea6c1de
--- /dev/null
+++ b/examples/xml/tagreader-with-features/structureparser.cpp
@@ -0,0 +1,56 @@
+/*
+*/
+
+#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;
+}
diff --git a/examples/xml/tagreader-with-features/structureparser.h b/examples/xml/tagreader-with-features/structureparser.h
new file mode 100644
index 0000000..32ada29
--- /dev/null
+++ b/examples/xml/tagreader-with-features/structureparser.h
@@ -0,0 +1,29 @@
+/*
+*/
+
+#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
diff --git a/examples/xml/tagreader-with-features/tagreader-with-features.pro b/examples/xml/tagreader-with-features/tagreader-with-features.pro
new file mode 100644
index 0000000..ffe7648
--- /dev/null
+++ b/examples/xml/tagreader-with-features/tagreader-with-features.pro
@@ -0,0 +1,11 @@
+TEMPLATE = app
+TARGET = tagreader-with-features
+
+CONFIG += qt warn_on release
+
+REQUIRES = xml large-config
+
+HEADERS = structureparser.h
+SOURCES = tagreader.cpp \
+ structureparser.cpp
+INTERFACES =
diff --git a/examples/xml/tagreader-with-features/tagreader.cpp b/examples/xml/tagreader-with-features/tagreader.cpp
new file mode 100644
index 0000000..32a7da0
--- /dev/null
+++ b/examples/xml/tagreader-with-features/tagreader.cpp
@@ -0,0 +1,74 @@
+/****************************************************************************
+**
+** Copyright (C) 2005-2008 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();
+}
diff --git a/examples/xml/tagreader-with-features/tagreader.doc b/examples/xml/tagreader-with-features/tagreader.doc
new file mode 100644
index 0000000..1d11dc2
--- /dev/null
+++ b/examples/xml/tagreader-with-features/tagreader.doc
@@ -0,0 +1,40 @@
+/*
+*/
+
+/*! \page tagreader-with-features-example.html
+
+ \ingroup xml-examples
+
+ \title Demonstration of SAX2 features
+
+ This example presents a small \link xml.html#sax2 SAX2 \endlink
+ 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 \link xml.html#sax2Namespaces features \endlink
+ \e http://xml.org/sax/features/namespaces and
+ \e http://xml.org/sax/features/namespace-prefixes are set.
+
+ This example is thoroughly explained in a
+ \link xml-sax-features-walkthrough.html walkthrough. \endlink
+
+ <hr>
+
+ Header file:
+
+ \include xml/tagreader-with-features/structureparser.h
+
+ <hr>
+
+ Implementation:
+
+ \include xml/tagreader-with-features/structureparser.cpp
+
+ <hr>
+
+ Main:
+
+ \include xml/tagreader-with-features/tagreader.cpp
+*/