author | zecke <zecke> | 2002-09-10 12:09:49 (UTC) |
---|---|---|
committer | zecke <zecke> | 2002-09-10 12:09:49 (UTC) |
commit | 6b77a1cdb9536b1c135eb86d53a6b2c22c19b0a4 (patch) (unidiff) | |
tree | 6ebc93c6432f4ed9d00ef1448b6a047ef522a79a /library/xmlreader.cpp | |
parent | d10cddb3c9ce75bc90b14add14bc133737fe35aa (diff) | |
download | opie-6b77a1cdb9536b1c135eb86d53a6b2c22c19b0a4.zip opie-6b77a1cdb9536b1c135eb86d53a6b2c22c19b0a4.tar.gz opie-6b77a1cdb9536b1c135eb86d53a6b2c22c19b0a4.tar.bz2 |
Qtopia1-6 merge
still to test
bic changes to be resolved
more changes to be made?
-rw-r--r-- | library/xmlreader.cpp | 19 |
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,128 +1,143 @@ | |||
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 | |||
22 | Node::Node() | 28 | Node::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 | ||
29 | Node::~Node() | 35 | Node::~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 | ||
41 | void Node::addChild( Node *child ) | 47 | void 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 | ||
54 | QString Node::attribute( const QString& name ) | 60 | QString Node::attribute( const QString& name ) |
55 | { | 61 | { |
56 | return attributes[name]; | 62 | return attributes[name]; |
57 | } | 63 | } |
58 | 64 | ||
59 | void Node::setAttributes( const QXmlAttributes &a ) | 65 | void 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 | ||
65 | QMap<QString, QString> Node::attributeMap() | 71 | QMap<QString, QString> Node::attributeMap() |
66 | { | 72 | { |
67 | return attributes; | 73 | return attributes; |
68 | } | 74 | } |
69 | 75 | ||
70 | QString Node::subData(const QString& tag) const | 76 | QString 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 | |||
81 | XmlHandler::XmlHandler() | 96 | XmlHandler::XmlHandler() |
82 | : node( 0 ), tree( 0 ) | 97 | : node( 0 ), tree( 0 ) |
83 | { | 98 | { |
84 | } | 99 | } |
85 | 100 | ||
86 | XmlHandler::~XmlHandler() | 101 | XmlHandler::~XmlHandler() |
87 | { | 102 | { |
88 | } | 103 | } |
89 | 104 | ||
90 | 105 | ||
91 | bool XmlHandler::startDocument() | 106 | bool 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 | ||
100 | bool XmlHandler::endDocument() | 115 | bool 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 | ||
108 | bool XmlHandler::startElement( const QString &, const QString &, | 123 | bool 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 | ||
122 | bool XmlHandler::endElement( const QString &, const QString &, const QString & ) | 137 | bool 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; |