diff options
Diffstat (limited to 'examples/xml/tagreader')
-rw-r--r-- | examples/xml/tagreader/animals.xml | 7 | ||||
-rw-r--r-- | examples/xml/tagreader/structureparser.cpp | 34 | ||||
-rw-r--r-- | examples/xml/tagreader/structureparser.h | 29 | ||||
-rw-r--r-- | examples/xml/tagreader/tagreader.cpp | 30 | ||||
-rw-r--r-- | examples/xml/tagreader/tagreader.doc | 35 | ||||
-rw-r--r-- | examples/xml/tagreader/tagreader.pro | 11 |
6 files changed, 146 insertions, 0 deletions
diff --git a/examples/xml/tagreader/animals.xml b/examples/xml/tagreader/animals.xml new file mode 100644 index 0000000..e128490 --- /dev/null +++ b/examples/xml/tagreader/animals.xml @@ -0,0 +1,7 @@ +<animals> +<mammals> + <monkeys> <gorilla/> <orangutan/> </monkeys> +</mammals> +<birds> <pigeon/> <penguin/> </birds> +</animals> + diff --git a/examples/xml/tagreader/structureparser.cpp b/examples/xml/tagreader/structureparser.cpp new file mode 100644 index 0000000..dd222b6 --- /dev/null +++ b/examples/xml/tagreader/structureparser.cpp @@ -0,0 +1,34 @@ +/**************************************************************************** +** +** Copyright (C) 1992-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 <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; +} diff --git a/examples/xml/tagreader/structureparser.h b/examples/xml/tagreader/structureparser.h new file mode 100644 index 0000000..31a6eb7 --- /dev/null +++ b/examples/xml/tagreader/structureparser.h @@ -0,0 +1,29 @@ +/**************************************************************************** +** +** Copyright (C) 1992-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. +** +*****************************************************************************/ + +#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 diff --git a/examples/xml/tagreader/tagreader.cpp b/examples/xml/tagreader/tagreader.cpp new file mode 100644 index 0000000..d337b1f --- /dev/null +++ b/examples/xml/tagreader/tagreader.cpp @@ -0,0 +1,30 @@ +/**************************************************************************** +** +** Copyright (C) 1992-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 <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; +} diff --git a/examples/xml/tagreader/tagreader.doc b/examples/xml/tagreader/tagreader.doc new file mode 100644 index 0000000..9a0bad0 --- /dev/null +++ b/examples/xml/tagreader/tagreader.doc @@ -0,0 +1,35 @@ +/* +*/ + +/*! \page tagreader-example.html + + \ingroup xml-examples + + \title A tiny SAX2 parser + + This example presents a small \link xml.html#sax2 SAX2 \endlink + 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 + \link xml-sax-walkthrough.html walkthrough. \endlink + + <hr> + + Header file: + + \include xml/tagreader/structureparser.h + + <hr> + + Implementation: + + \include xml/tagreader/structureparser.cpp + + <hr> + + Main: + + \include xml/tagreader/tagreader.cpp +*/ diff --git a/examples/xml/tagreader/tagreader.pro b/examples/xml/tagreader/tagreader.pro new file mode 100644 index 0000000..b6ebf8b --- /dev/null +++ b/examples/xml/tagreader/tagreader.pro @@ -0,0 +1,11 @@ +TEMPLATE = app +TARGET = tagreader + +CONFIG += qt console warn_on release + +REQUIRES = xml large-config + +HEADERS = structureparser.h +SOURCES = tagreader.cpp \ + structureparser.cpp +INTERFACES = |