summaryrefslogtreecommitdiffstats
path: root/examples/xml/tagreader-with-features
diff options
context:
space:
mode:
authorTimothy Pearson <[email protected]>2011-11-08 12:31:36 -0600
committerTimothy Pearson <[email protected]>2011-11-08 12:31:36 -0600
commitd796c9dd933ab96ec83b9a634feedd5d32e1ba3f (patch)
tree6e3dcca4f77e20ec8966c666aac7c35bd4704053 /examples/xml/tagreader-with-features
downloadtqt3-d796c9dd933ab96ec83b9a634feedd5d32e1ba3f.tar.gz
tqt3-d796c9dd933ab96ec83b9a634feedd5d32e1ba3f.zip
Test conversion to TQt3 from Qt3 8c6fc1f8e35fd264dd01c582ca5e7549b32ab731
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 000000000..4d1303dd1
--- /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 000000000..3bbd2a9c9
--- /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( TQListView * t )
+ : TQXmlDefaultHandler()
+{
+ setListView( t );
+}
+
+void StructureParser::setListView( TQListView * t )
+{
+ table = t;
+ table->setSorting( -1 );
+ table->addColumn( "Qualified name" );
+ table->addColumn( "Namespace" );
+}
+
+bool StructureParser::startElement( const TQString& namespaceURI,
+ const TQString& ,
+ const TQString& qName,
+ const TQXmlAttributes& attributes)
+{
+ TQListViewItem * element;
+
+ if ( ! stack.isEmpty() ){
+ TQListViewItem *lastChild = stack.top()->firstChild();
+ if ( lastChild ) {
+ while ( lastChild->nextSibling() )
+ lastChild = lastChild->nextSibling();
+ }
+ element = new TQListViewItem( stack.top(), lastChild, qName, namespaceURI );
+ } else {
+ element = new TQListViewItem( table, qName, namespaceURI );
+ }
+ stack.push( element );
+ element->setOpen( TRUE );
+
+ if ( attributes.length() > 0 ) {
+ for ( int i = 0 ; i < attributes.length(); i++ ) {
+ new TQListViewItem( element, attributes.qName(i), attributes.uri(i) );
+ }
+ }
+ return TRUE;
+}
+
+bool StructureParser::endElement( const TQString&, const TQString&,
+ const TQString& )
+{
+ 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 000000000..9ab8ec2af
--- /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 TQListView;
+class TQListViewItem;
+class TQString;
+
+class StructureParser: public TQXmlDefaultHandler
+{
+public:
+ StructureParser( TQListView * );
+ bool startElement( const TQString&, const TQString&, const TQString& ,
+ const TQXmlAttributes& );
+ bool endElement( const TQString&, const TQString&, const TQString& );
+
+ void setListView( TQListView * );
+
+private:
+ TQPtrStack<TQListViewItem> stack;
+ TQListView * 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 000000000..ffe7648d7
--- /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 000000000..866879a4f
--- /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 TQt. 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 )
+{
+ TQApplication app( argc, argv );
+
+ TQFile xmlFile( argc == 2 ? argv[1] : "fnord.xml" );
+ TQXmlInputSource source( &xmlFile );
+
+ TQXmlSimpleReader reader;
+
+ TQGrid * container = new TQGrid( 3 );
+
+ TQListView * nameSpace = new TQListView( container, "table_namespace" );
+ StructureParser * handler = new StructureParser( nameSpace );
+ reader.setContentHandler( handler );
+ reader.parse( source );
+
+ TQListView * namespacePrefix = new TQListView( container,
+ "table_namespace_prefix" );
+ handler->setListView( namespacePrefix );
+ reader.setFeature( "http://xml.org/sax/features/namespace-prefixes",
+ TRUE );
+ source.reset();
+ reader.parse( source );
+
+ TQListView * prefix = new TQListView( container, "table_prefix");
+ handler->setListView( prefix );
+ reader.setFeature( "http://xml.org/sax/features/namespaces", FALSE );
+ source.reset();
+ reader.parse( source );
+
+ // namespace label
+ (void) new TQLabel(
+ "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 TQLabel(
+ "\n"
+ "http://xml.org/sax/features/namespaces: TRUE\n"
+ "http://xml.org/sax/features/namespace-prefixes: TRUE\n",
+ container );
+
+ // prefix label
+ (void) new TQLabel(
+ "\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 000000000..1d11dc260
--- /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
+*/