lib

KoXmlReader.h
1/* This file is part of the KDE project
2 Copyright (C) 2005 Ariya Hidayat <ariya@kde.org>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18*/
19
20#ifndef KOFFICE_XMLREADER
21#define KOFFICE_XMLREADER
22
23// use standard TQDom, useful to test KoXml classes against TQt's TQDom
24//#define KOXML_USE_TQDOM
25
26#include <tqdom.h>
27#include <koffice_export.h>
28
29#ifdef KOXML_USE_TQDOM
30
31#define KoXmlNode TQDomNode
32#define KoXmlElement TQDomElement
33#define KoXmlText TQDomText
34#define KoXmlCDATASection TQDomCDATASection
35#define KoXmlDocument TQDomDocument
36
37#else
38
39class TQIODevice;
40class TQString;
41class TQTextStream;
42class TQXmlReader;
43class TQXmlInputSource;
44
45class KoXmlElement;
46class KoXmlText;
48class KoXmlDocument;
49class KoXmlNodeData;
50
64class KOFFICECORE_EXPORT KoXmlNode
65{
66public:
67
68 enum NodeType
69 {
70 NullNode = 0,
71 ElementNode,
72 TextNode,
73 CDATASectionNode,
74 ProcessingInstructionNode,
75 DocumentNode
76 };
77
78 KoXmlNode();
79 KoXmlNode( const KoXmlNode& node );
80 KoXmlNode& operator=( const KoXmlNode& node );
81 bool operator== ( const KoXmlNode& ) const;
82 bool operator!= ( const KoXmlNode& ) const;
83 virtual ~KoXmlNode();
84
85 virtual KoXmlNode::NodeType nodeType() const;
86 virtual bool isNull() const;
87 virtual bool isElement() const;
88 virtual bool isText() const;
89 virtual bool isCDATASection() const;
90 virtual bool isDocument() const;
91
92 void clear();
93 KoXmlElement toElement();
94 KoXmlText toText();
95 KoXmlCDATASection toCDATASection();
96 KoXmlDocument toDocument();
97
98 virtual TQString nodeName() const;
99 virtual TQString namespaceURI() const;
100 virtual TQString prefix() const;
101 virtual TQString localName() const;
102
103 KoXmlDocument ownerDocument() const;
104 KoXmlNode parentNode() const;
105
106 bool hasChildNodes() const;
107 KoXmlNode firstChild() const;
108 KoXmlNode lastChild() const;
109 KoXmlNode nextSibling() const;
110 KoXmlNode previousSibling() const;
111
112 KoXmlNode namedItem( const TQString& name ) const;
113 KoXmlNode namedItemNS( const TQString& nsURI, const TQString& name ) const;
114
120 void load( int depth=1 );
121
125 void unload();
126
127protected:
128 KoXmlNodeData* d;
129 KoXmlNode( KoXmlNodeData* );
130};
131
139
140class KOFFICECORE_EXPORT KoXmlElement: public KoXmlNode
141{
142public:
143 KoXmlElement();
144 KoXmlElement( const KoXmlElement& element );
145 KoXmlElement& operator=( const KoXmlElement& element );
146 virtual ~KoXmlElement();
147 bool operator== ( const KoXmlElement& ) const;
148 bool operator!= ( const KoXmlElement& ) const;
149
150 TQString tagName() const;
151 TQString text() const;
152 virtual bool isElement() const;
153
154 TQString attribute( const TQString& name ) const;
155 TQString attribute( const TQString& name, const TQString& defaultValue ) const;
156 TQString attributeNS( const TQString& namespaceURI, const TQString& localName,
157 const TQString& defaultValue ) const;
158 bool hasAttribute( const TQString& name ) const;
159 bool hasAttributeNS( const TQString& namespaceURI, const TQString& localName ) const;
160
161private:
162 friend class KoXmlNode;
163 friend class KoXmlDocument;
164 KoXmlElement( KoXmlNodeData* );
165};
166
171class KOFFICECORE_EXPORT KoXmlText: public KoXmlNode
172{
173public:
174 KoXmlText();
175 KoXmlText( const KoXmlText& text );
176 KoXmlText& operator=( const KoXmlText& text );
177 virtual ~KoXmlText();
178
179 TQString data() const;
180 void setData( const TQString& data );
181 virtual bool isText() const;
182
183private:
184 friend class KoXmlNode;
185 friend class KoXmlDocument;
186 KoXmlText( KoXmlNodeData* );
187};
188
193class KOFFICECORE_EXPORT KoXmlCDATASection: public KoXmlText
194{
195public:
196 KoXmlCDATASection();
197 KoXmlCDATASection( const KoXmlCDATASection& cdata );
198 KoXmlCDATASection& operator=( const KoXmlCDATASection& cdata );
199 virtual ~KoXmlCDATASection();
200
201 virtual bool isCDATASection() const;
202
203private:
204 friend class KoXmlNode;
205 friend class KoXmlDocument;
206 KoXmlCDATASection( KoXmlNodeData* );
207};
208
220
221class KOFFICECORE_EXPORT KoXmlDocument: public KoXmlNode
222{
223public:
224 KoXmlDocument();
225 KoXmlDocument( const KoXmlDocument& node );
226 KoXmlDocument& operator=( const KoXmlDocument& node );
227 bool operator==( const KoXmlDocument& ) const;
228 bool operator!=( const KoXmlDocument& ) const;
229 virtual ~KoXmlDocument();
230
231 virtual bool isDocument() const;
232
233 KoXmlElement documentElement() const;
234
235 void setFastLoading( bool f );
236 bool fastLoading() const;
237
238 bool setContent( TQIODevice* device, bool namespaceProcessing,
239 TQString* errorMsg = 0, int* errorLine = 0, int* errorColumn = 0 );
240 bool setContent( TQIODevice* device,
241 TQString* errorMsg = 0, int* errorLine = 0, int* errorColumn = 0 );
242 bool setContent( TQXmlInputSource *source, TQXmlReader *reader,
243 TQString* errorMsg = 0, int* errorLine = 0, int* errorColumn = 0 );
244
245// bool setContent( const TQCString& text, bool namespaceProcessing, TQString *errorMsg=0, int *errorLine=0, int *errorColumn=0 );
246// bool setContent( const TQByteArray& text, bool namespaceProcessing, TQString *errorMsg=0, int *errorLine=0, int *errorColumn=0 );
247// bool setContent( const TQString& text, bool namespaceProcessing, TQString *errorMsg=0, int *errorLine=0, int *errorColumn=0 );
248// bool setContent( TQIODevice* dev, bool namespaceProcessing, TQString *errorMsg=0, int *errorLine=0, int *errorColumn=0 );
249// bool setContent( const TQCString& text, TQString *errorMsg=0, int *errorLine=0, int *errorColumn=0 );
250// bool setContent( const TQByteArray& text, TQString *errorMsg=0, int *errorLine=0, int *errorColumn=0 );
251// bool setContent( const TQString& text, TQString *errorMsg=0, int *errorLine=0,
252// int *errorColumn=0 );
253
254
255private:
256 friend class KoXmlNode;
257 KoXmlDocument( KoXmlNodeData* );
258};
259
260#endif // KOXML_USE_TQDOM
261
288namespace KoXml {
289
298 KOFFICECORE_EXPORT KoXmlElement namedItemNS( const KoXmlNode& node,
299 const char* nsURI, const char* localName );
300
305 KOFFICECORE_EXPORT void load( KoXmlNode& node, int depth = 1 );
306
311 KOFFICECORE_EXPORT void unload( KoXmlNode& node );
312
313}
314
315#define forEachElement( elem, parent ) \
316 for ( KoXmlNode _node = parent.firstChild(); !_node.isNull(); _node = _node.nextSibling() ) \
317 if ( !( elem = _node.toElement() ).isNull() )
318
319
320#endif // KOFFICE_XMLREADER
KoXmlCDATASection represents a CDATA section in a DOM tree.
KoXmlDocument represents an XML document, structured in a DOM tree.
KoXmlElement represents a tag element in a DOM tree.
KoXmlNode represents a node in a DOM tree.
Definition KoXmlReader.h:65
void load(int depth=1)
Loads all child nodes (if any) of this node.
void unload()
Releases all child nodes of this node.
KoXmlText represents a text in a DOM tree.
This namespace contains a few convenience functions to simplify code using TQDom (when loading OASIS ...
KOFFICECORE_EXPORT void unload(KoXmlNode &node)
Unload child nodes of specified node.
KOFFICECORE_EXPORT void load(KoXmlNode &node, int depth=1)
Explicitly load child nodes of specified node, up to given depth.
KOFFICECORE_EXPORT KoXmlElement namedItemNS(const KoXmlNode &node, const char *nsURI, const char *localName)
A namespace-aware version of TQDomNode::namedItem(), which also takes care of casting to a TQDomEleme...