xmlreader.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
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 }
This file is part of the documentation for OPIE Version 1.5.5.