summaryrefslogtreecommitdiff
path: root/library/xmlreader.cpp
Unidiff
Diffstat (limited to 'library/xmlreader.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--library/xmlreader.cpp19
1 files changed, 17 insertions, 2 deletions
diff --git a/library/xmlreader.cpp b/library/xmlreader.cpp
index 1ae4485..1caab28 100644
--- a/library/xmlreader.cpp
+++ b/library/xmlreader.cpp
@@ -1,137 +1,152 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of the Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20#include "xmlreader.h" 20#include "xmlreader.h"
21 21
22/*! \class Node xmlreader.h
23 \brief A single element in an XML structure defined by XmlHandler
24
25 \ingroup qtopiaemb
26 */
27
22Node::Node() 28Node::Node()
23 : parent( 0 ), prev( 0 ), 29 : parent( 0 ), prev( 0 ),
24 next( 0 ), first( 0 ), last( 0 ) 30 next( 0 ), first( 0 ), last( 0 )
25{ 31{
26} 32}
27 33
28 34
29Node::~Node() 35Node::~Node()
30{ 36{
31 Node *n = first, *m; 37 Node *n = first, *m;
32 38
33 while ( n ) { 39 while ( n ) {
34 m = n->next; 40 m = n->next;
35 delete n; 41 delete n;
36 n = m; 42 n = m;
37 } 43 }
38} 44}
39 45
40 46
41void Node::addChild( Node *child ) 47void Node::addChild( Node *child )
42{ 48{
43 child->parent = this; 49 child->parent = this;
44 50
45 if ( last ) 51 if ( last )
46 last->next = child; 52 last->next = child;
47 child->prev = last; 53 child->prev = last;
48 54
49 if ( !first ) 55 if ( !first )
50 first = child; 56 first = child;
51 last = child; 57 last = child;
52} 58}
53 59
54QString Node::attribute( const QString& name ) 60QString Node::attribute( const QString& name )
55{ 61{
56 return attributes[name]; 62 return attributes[name];
57} 63}
58 64
59void Node::setAttributes( const QXmlAttributes &a ) 65void Node::setAttributes( const QXmlAttributes &a )
60{ 66{
61 for ( int i = 0; i < a.length(); i++ ) 67 for ( int i = 0; i < a.length(); i++ )
62 attributes[ a.qName( i ) ] = a.value( i ); 68 attributes[ a.qName( i ) ] = a.value( i );
63} 69}
64 70
65QMap<QString, QString> Node::attributeMap() 71QMap<QString, QString> Node::attributeMap()
66{ 72{
67 return attributes; 73 return attributes;
68} 74}
69 75
70QString Node::subData(const QString& tag) const 76QString Node::subData(const QString& tag) const
71{ 77{
72 Node* c = firstChild(); 78 Node* c = firstChild();
73 while ( c ) { 79 while ( c ) {
74 if ( c->tagName() == tag ) 80 if ( c->tagName() == tag )
75 return c->data(); 81 return c->data();
76 c = c->nextNode(); 82 c = c->nextNode();
77 } 83 }
78 return QString::null; 84 return QString::null;
79} 85}
80 86
87/*! \class XmlHandler xmlreader.h
88 \brief XML document structure holder
89
90 This class provides a Node structure that developers can read their
91 xml data into.
92
93 \ingroup qtopiaemb
94*/
95
81XmlHandler::XmlHandler() 96XmlHandler::XmlHandler()
82 : node( 0 ), tree( 0 ) 97 : node( 0 ), tree( 0 )
83{ 98{
84} 99}
85 100
86XmlHandler::~XmlHandler() 101XmlHandler::~XmlHandler()
87{ 102{
88} 103}
89 104
90 105
91bool XmlHandler::startDocument() 106bool XmlHandler::startDocument()
92{ 107{
93 tree = node = new Node; 108 tree = node = new Node;
94 node->setTagName( "DOCUMENT" ); 109 node->setTagName( "DOCUMENT" );
95 110
96 return TRUE; 111 return TRUE;
97} 112}
98 113
99 114
100bool XmlHandler::endDocument() 115bool XmlHandler::endDocument()
101{ 116{
102 if ( node != tree ) 117 if ( node != tree )
103 return FALSE; 118 return FALSE;
104 119
105 return TRUE; 120 return TRUE;
106} 121}
107 122
108bool XmlHandler::startElement( const QString &, const QString &, 123bool XmlHandler::startElement( const QString &, const QString &,
109 const QString &qName, const QXmlAttributes &attr ) 124 const QString &qName, const QXmlAttributes &attr )
110{ 125{
111 Node *nnode = new Node; 126 Node *nnode = new Node;
112 nnode->setAttributes( attr ); 127 nnode->setAttributes( attr );
113 nnode->setTagName( qName ); 128 nnode->setTagName( qName );
114 129
115 node->addChild( nnode ); 130 node->addChild( nnode );
116 node = nnode; 131 node = nnode;
117 132
118 return TRUE; 133 return TRUE;
119} 134}
120 135
121 136
122bool XmlHandler::endElement( const QString &, const QString &, const QString & ) 137bool XmlHandler::endElement( const QString &, const QString &, const QString & )
123{ 138{
124 if ( node == tree ) 139 if ( node == tree )
125 return FALSE; 140 return FALSE;
126 141
127 node = node->parentNode(); 142 node = node->parentNode();
128 return TRUE; 143 return TRUE;
129} 144}
130 145
131 146
132bool XmlHandler::characters( const QString &ch ) 147bool XmlHandler::characters( const QString &ch )
133{ 148{
134 node->appendData( ch ); 149 node->appendData( ch );
135 150
136 return TRUE; 151 return TRUE;
137} 152}