Qtopia library API Documentation

xmlreader.cpp

00001 /**********************************************************************
00002 ** Copyright (C) 2000-2002 Trolltech AS.  All rights reserved.
00003 **
00004 ** This file is part of the Qtopia Environment.
00005 **
00006 ** This file may be distributed and/or modified under the terms of the
00007 ** GNU General Public License version 2 as published by the Free Software
00008 ** Foundation and appearing in the file LICENSE.GPL included in the
00009 ** packaging of this file.
00010 **
00011 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00012 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00013 **
00014 ** See http://www.trolltech.com/gpl/ for GPL licensing information.
00015 **
00016 ** Contact info@trolltech.com if any conditions of this licensing are
00017 ** not clear to you.
00018 **
00019 **********************************************************************/
00020 #include "xmlreader.h"
00021 
00028 Node::Node()
00029     : parent( 0 ), prev( 0 ),
00030       next( 0 ), first( 0 ), last( 0 )
00031 {
00032 }
00033 
00034 
00035 Node::~Node()
00036 {
00037     Node *n = first, *m;
00038 
00039     while ( n ) {
00040     m = n->next;
00041     delete n;
00042     n = m;
00043     }
00044 }
00045 
00046 
00047 void Node::addChild( Node *child )
00048 {
00049     child->parent = this;
00050 
00051     if ( last )
00052     last->next = child;
00053     child->prev = last;
00054 
00055     if ( !first )
00056     first = child;
00057     last = child;
00058 }
00059 
00060 QString Node::attribute( const QString& name )
00061 {
00062     return attributes[name];
00063 }
00064 
00065 void Node::setAttributes( const QXmlAttributes &a )
00066 {
00067     for ( int i = 0; i < a.length(); i++ )
00068     attributes[ a.qName( i ) ] = a.value( i );
00069 }
00070 
00071 QMap<QString, QString> Node::attributeMap()
00072 {
00073     return attributes;
00074 }
00075 
00076 QString Node::subData(const QString& tag) const
00077 {
00078     Node* c = firstChild();
00079     while ( c ) {
00080     if ( c->tagName() == tag )
00081         return c->data();
00082     c = c->nextNode();
00083     }
00084     return QString::null;
00085 }
00086 
00096 XmlHandler::XmlHandler()
00097     : node( 0 ), tree( 0 )
00098 {
00099 }
00100 
00101 XmlHandler::~XmlHandler()
00102 {
00103 }
00104 
00105 
00106 bool XmlHandler::startDocument()
00107 {
00108     tree = node = new Node;
00109     node->setTagName( "DOCUMENT" );
00110 
00111     return TRUE;
00112 }
00113 
00114 
00115 bool XmlHandler::endDocument()
00116 {
00117     if ( node != tree )
00118     return FALSE;
00119 
00120     return TRUE;
00121 }
00122 
00123 bool XmlHandler::startElement( const QString &, const QString &,
00124                    const QString &qName, const QXmlAttributes &attr )
00125 {
00126     Node *nnode = new Node;
00127     nnode->setAttributes( attr );
00128     nnode->setTagName( qName );
00129 
00130     node->addChild( nnode );
00131     node = nnode;
00132 
00133     return TRUE;
00134 }
00135 
00136 
00137 bool XmlHandler::endElement( const QString &, const QString &, const QString & )
00138 {
00139     if ( node == tree )
00140     return FALSE;
00141 
00142     node = node->parentNode();
00143     return TRUE;
00144 }
00145 
00146 
00147 bool XmlHandler::characters( const QString &ch )
00148 {
00149     node->appendData( ch );
00150 
00151     return TRUE;
00152 }
KDE Logo
This file is part of the documentation for OPIE Version 1.5.5.
Documentation copyright © 1997-2003 the KDE developers. 2003 OPIE developers
Generated on Tue Feb 10 20:24:09 2004 by doxygen 1.3.5 written by Dimitri van Heesch, © 1997-2001