1 | /****************************************************************************
|
---|
2 | ** $Id: qdom.cpp,v 1.1 2004/02/29 00:05:06 justin Exp $
|
---|
3 | **
|
---|
4 | ** Implementation of QDomDocument and related classes.
|
---|
5 | **
|
---|
6 | ** Created : 000518
|
---|
7 | **
|
---|
8 | ** Copyright (C) 1992-2002 Trolltech AS. All rights reserved.
|
---|
9 | **
|
---|
10 | ** This file is part of the xml module of the Qt GUI Toolkit.
|
---|
11 | **
|
---|
12 | ** This file may be distributed under the terms of the Q Public License
|
---|
13 | ** as defined by Trolltech AS of Norway and appearing in the file
|
---|
14 | ** LICENSE.QPL included in the packaging of this file.
|
---|
15 | **
|
---|
16 | ** This file may be distributed and/or modified under the terms of the
|
---|
17 | ** GNU General Public License version 2 as published by the Free Software
|
---|
18 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
19 | ** packaging of this file.
|
---|
20 | **
|
---|
21 | ** Licensees holding valid Qt Enterprise Edition licenses may use this
|
---|
22 | ** file in accordance with the Qt Commercial License Agreement provided
|
---|
23 | ** with the Software.
|
---|
24 | **
|
---|
25 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
|
---|
26 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
---|
27 | **
|
---|
28 | ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
|
---|
29 | ** information about Qt Commercial License Agreements.
|
---|
30 | ** See http://www.trolltech.com/qpl/ for QPL licensing information.
|
---|
31 | ** See http://www.trolltech.com/gpl/ for GPL licensing information.
|
---|
32 | **
|
---|
33 | ** Contact info@trolltech.com if any conditions of this licensing are
|
---|
34 | ** not clear to you.
|
---|
35 | **
|
---|
36 | **********************************************************************/
|
---|
37 |
|
---|
38 | #include "qdom.h"
|
---|
39 |
|
---|
40 | #ifndef QT_NO_DOM
|
---|
41 |
|
---|
42 | #include "qxml.h"
|
---|
43 | #include "qptrlist.h"
|
---|
44 | #include "qdict.h"
|
---|
45 | #include "qtextstream.h"
|
---|
46 | #include "qtextcodec.h"
|
---|
47 | #include "qiodevice.h"
|
---|
48 | #include "qregexp.h"
|
---|
49 | #include "qbuffer.h"
|
---|
50 |
|
---|
51 | namespace PsiXml {
|
---|
52 |
|
---|
53 | /*
|
---|
54 | ### old todo comments -- I don't know if they still apply...
|
---|
55 |
|
---|
56 | If the document dies, remove all pointers to it from children
|
---|
57 | which can not be deleted at this time.
|
---|
58 |
|
---|
59 | If a node dies and has direct children which can not be deleted,
|
---|
60 | then remove the pointer to the parent.
|
---|
61 |
|
---|
62 | createElement and friends create double reference counts.
|
---|
63 | */
|
---|
64 |
|
---|
65 | /*
|
---|
66 | Reference counting:
|
---|
67 |
|
---|
68 | Some simple rules:
|
---|
69 | 1) If an intern object returns a pointer to another intern object
|
---|
70 | then the reference count of the returned object is not increased.
|
---|
71 | 2) If an extern object is created and gets a pointer to some intern
|
---|
72 | object, then the extern object increases the intern objects reference count.
|
---|
73 | 3) If an extern object is deleted, then it decreases the reference count
|
---|
74 | on its associated intern object and deletes it if nobody else hold references
|
---|
75 | on the intern object.
|
---|
76 | */
|
---|
77 |
|
---|
78 |
|
---|
79 | /*
|
---|
80 | Helper to split a qualified name in the prefix and local name.
|
---|
81 | */
|
---|
82 | static void qt_split_namespace( QString& prefix, QString& name, const QString& qName, bool hasURI )
|
---|
83 | {
|
---|
84 | int i = qName.find( ':' );
|
---|
85 | if ( i == -1 ) {
|
---|
86 | if ( hasURI )
|
---|
87 | prefix = "";
|
---|
88 | else
|
---|
89 | prefix = QString::null;
|
---|
90 | name = qName;
|
---|
91 | } else {
|
---|
92 | prefix = qName.left( i );
|
---|
93 | name = qName.mid( i + 1 );
|
---|
94 | }
|
---|
95 | }
|
---|
96 |
|
---|
97 | /*
|
---|
98 | Counter for the QDomNodeListPrivate timestamps.
|
---|
99 | */
|
---|
100 | static volatile long qt_nodeListTime = 0;
|
---|
101 |
|
---|
102 | /**************************************************************
|
---|
103 | *
|
---|
104 | * Private class declerations
|
---|
105 | *
|
---|
106 | **************************************************************/
|
---|
107 |
|
---|
108 | class QDomImplementationPrivate : public QShared
|
---|
109 | {
|
---|
110 | public:
|
---|
111 | QDomImplementationPrivate();
|
---|
112 | ~QDomImplementationPrivate();
|
---|
113 |
|
---|
114 | QDomImplementationPrivate* clone();
|
---|
115 |
|
---|
116 | };
|
---|
117 |
|
---|
118 | class QDomNodePrivate : public QShared
|
---|
119 | {
|
---|
120 | public:
|
---|
121 | QDomNodePrivate( QDomDocumentPrivate*, QDomNodePrivate* parent = 0 );
|
---|
122 | QDomNodePrivate( QDomNodePrivate* n, bool deep );
|
---|
123 | virtual ~QDomNodePrivate();
|
---|
124 |
|
---|
125 | QString nodeName() const { return name; }
|
---|
126 | QString nodeValue() const { return value; }
|
---|
127 | virtual void setNodeValue( const QString& v ) { value = v; }
|
---|
128 |
|
---|
129 | QDomDocumentPrivate* ownerDocument();
|
---|
130 | void setOwnerDocument( QDomDocumentPrivate* doc );
|
---|
131 |
|
---|
132 | virtual QDomNamedNodeMapPrivate* attributes();
|
---|
133 | virtual bool hasAttributes() { return FALSE; }
|
---|
134 | virtual QDomNodePrivate* insertBefore( QDomNodePrivate* newChild, QDomNodePrivate* refChild );
|
---|
135 | virtual QDomNodePrivate* insertAfter( QDomNodePrivate* newChild, QDomNodePrivate* refChild );
|
---|
136 | virtual QDomNodePrivate* replaceChild( QDomNodePrivate* newChild, QDomNodePrivate* oldChild );
|
---|
137 | virtual QDomNodePrivate* removeChild( QDomNodePrivate* oldChild );
|
---|
138 | virtual QDomNodePrivate* appendChild( QDomNodePrivate* newChild );
|
---|
139 |
|
---|
140 | QDomNodePrivate* namedItem( const QString& name );
|
---|
141 |
|
---|
142 | virtual QDomNodePrivate* cloneNode( bool deep = TRUE );
|
---|
143 | virtual void normalize();
|
---|
144 | virtual void clear();
|
---|
145 |
|
---|
146 | QDomNodePrivate* parent() { return hasParent ? ownerNode : 0; }
|
---|
147 | void setParent( QDomNodePrivate *p ) { ownerNode = p; hasParent = TRUE; }
|
---|
148 | void setNoParent() {
|
---|
149 | ownerNode = hasParent ? (QDomNodePrivate*)ownerDocument() : 0;
|
---|
150 | hasParent = FALSE;
|
---|
151 | }
|
---|
152 |
|
---|
153 | // Dynamic cast
|
---|
154 | virtual bool isAttr() { return FALSE; }
|
---|
155 | virtual bool isCDATASection() { return FALSE; }
|
---|
156 | virtual bool isDocumentFragment() { return FALSE; }
|
---|
157 | virtual bool isDocument() { return FALSE; }
|
---|
158 | virtual bool isDocumentType() { return FALSE; }
|
---|
159 | virtual bool isElement() { return FALSE; }
|
---|
160 | virtual bool isEntityReference() { return FALSE; }
|
---|
161 | virtual bool isText() { return FALSE; }
|
---|
162 | virtual bool isEntity() { return FALSE; }
|
---|
163 | virtual bool isNotation() { return FALSE; }
|
---|
164 | virtual bool isProcessingInstruction() { return FALSE; }
|
---|
165 | virtual bool isCharacterData() { return FALSE; }
|
---|
166 | virtual bool isComment() { return FALSE; }
|
---|
167 | virtual QDomNode::NodeType nodeType() const { return QDomNode::BaseNode; }
|
---|
168 |
|
---|
169 | virtual void save( QTextStream&, int, int ) const;
|
---|
170 |
|
---|
171 | // Variables
|
---|
172 | QDomNodePrivate* prev;
|
---|
173 | QDomNodePrivate* next;
|
---|
174 | QDomNodePrivate* ownerNode; // either the node's parent or the node's owner document
|
---|
175 | QDomNodePrivate* first;
|
---|
176 | QDomNodePrivate* last;
|
---|
177 |
|
---|
178 | QString name; // this is the local name if prefix != null
|
---|
179 | QString value;
|
---|
180 | QString prefix; // set this only for ElementNode and AttributeNode
|
---|
181 | QString namespaceURI; // set this only for ElementNode and AttributeNode
|
---|
182 | bool createdWithDom1Interface;
|
---|
183 | bool hasParent;
|
---|
184 | };
|
---|
185 |
|
---|
186 | class QDomNodeListPrivate : public QShared
|
---|
187 | {
|
---|
188 | public:
|
---|
189 | QDomNodeListPrivate( QDomNodePrivate* );
|
---|
190 | QDomNodeListPrivate( QDomNodePrivate*, const QString& );
|
---|
191 | QDomNodeListPrivate( QDomNodePrivate*, const QString&, const QString& );
|
---|
192 | virtual ~QDomNodeListPrivate();
|
---|
193 |
|
---|
194 | virtual bool operator== ( const QDomNodeListPrivate& ) const;
|
---|
195 | virtual bool operator!= ( const QDomNodeListPrivate& ) const;
|
---|
196 |
|
---|
197 | void createList();
|
---|
198 | virtual QDomNodePrivate* item( int index );
|
---|
199 | virtual uint length() const;
|
---|
200 |
|
---|
201 | QDomNodePrivate* node_impl;
|
---|
202 | QString tagname;
|
---|
203 | QString nsURI;
|
---|
204 | QPtrList<QDomNodePrivate> list;
|
---|
205 | long timestamp;
|
---|
206 | };
|
---|
207 |
|
---|
208 | class QDomNamedNodeMapPrivate : public QShared
|
---|
209 | {
|
---|
210 | public:
|
---|
211 | QDomNamedNodeMapPrivate( QDomNodePrivate* );
|
---|
212 | ~QDomNamedNodeMapPrivate();
|
---|
213 |
|
---|
214 | QDomNodePrivate* namedItem( const QString& name ) const;
|
---|
215 | QDomNodePrivate* namedItemNS( const QString& nsURI, const QString& localName ) const;
|
---|
216 | QDomNodePrivate* setNamedItem( QDomNodePrivate* arg );
|
---|
217 | QDomNodePrivate* setNamedItemNS( QDomNodePrivate* arg );
|
---|
218 | QDomNodePrivate* removeNamedItem( const QString& name );
|
---|
219 | QDomNodePrivate* item( int index ) const;
|
---|
220 | uint length() const;
|
---|
221 | bool contains( const QString& name ) const;
|
---|
222 | bool containsNS( const QString& nsURI, const QString & localName ) const;
|
---|
223 |
|
---|
224 | /**
|
---|
225 | * Remove all children from the map.
|
---|
226 | */
|
---|
227 | void clearMap();
|
---|
228 | bool isReadOnly() { return readonly; }
|
---|
229 | void setReadOnly( bool r ) { readonly = r; }
|
---|
230 | bool isAppendToParent() { return appendToParent; }
|
---|
231 | /**
|
---|
232 | * If TRUE, then the node will redirect insert/remove calls
|
---|
233 | * to its parent by calling QDomNodePrivate::appendChild or removeChild.
|
---|
234 | * In addition the map wont increase or decrease the reference count
|
---|
235 | * of the nodes it contains.
|
---|
236 | *
|
---|
237 | * By default this value is FALSE and the map will handle reference counting
|
---|
238 | * by itself.
|
---|
239 | */
|
---|
240 | void setAppendToParent( bool b ) { appendToParent = b; }
|
---|
241 |
|
---|
242 | /**
|
---|
243 | * Creates a copy of the map. It is a deep copy
|
---|
244 | * that means that all children are cloned.
|
---|
245 | */
|
---|
246 | QDomNamedNodeMapPrivate* clone( QDomNodePrivate* parent );
|
---|
247 |
|
---|
248 | // Variables
|
---|
249 | QDict<QDomNodePrivate> map;
|
---|
250 | QDomNodePrivate* parent;
|
---|
251 | bool readonly;
|
---|
252 | bool appendToParent;
|
---|
253 | };
|
---|
254 |
|
---|
255 | class QDomDocumentTypePrivate : public QDomNodePrivate
|
---|
256 | {
|
---|
257 | public:
|
---|
258 | QDomDocumentTypePrivate( QDomDocumentPrivate*, QDomNodePrivate* parent = 0 );
|
---|
259 | QDomDocumentTypePrivate( QDomDocumentTypePrivate* n, bool deep );
|
---|
260 | ~QDomDocumentTypePrivate();
|
---|
261 | void init();
|
---|
262 |
|
---|
263 | // Reimplemented from QDomNodePrivate
|
---|
264 | QDomNodePrivate* cloneNode( bool deep = TRUE );
|
---|
265 | QDomNodePrivate* insertBefore( QDomNodePrivate* newChild, QDomNodePrivate* refChild );
|
---|
266 | QDomNodePrivate* insertAfter( QDomNodePrivate* newChild, QDomNodePrivate* refChild );
|
---|
267 | QDomNodePrivate* replaceChild( QDomNodePrivate* newChild, QDomNodePrivate* oldChild );
|
---|
268 | QDomNodePrivate* removeChild( QDomNodePrivate* oldChild );
|
---|
269 | QDomNodePrivate* appendChild( QDomNodePrivate* newChild );
|
---|
270 |
|
---|
271 | bool isDocumentType() { return TRUE; }
|
---|
272 | QDomNode::NodeType nodeType() const { return QDomNode::DocumentTypeNode; }
|
---|
273 |
|
---|
274 | void save( QTextStream& s, int, int ) const;
|
---|
275 |
|
---|
276 | // Variables
|
---|
277 | QDomNamedNodeMapPrivate* entities;
|
---|
278 | QDomNamedNodeMapPrivate* notations;
|
---|
279 | QString publicId;
|
---|
280 | QString systemId;
|
---|
281 | QString internalSubset;
|
---|
282 | };
|
---|
283 |
|
---|
284 | class QDomDocumentFragmentPrivate : public QDomNodePrivate
|
---|
285 | {
|
---|
286 | public:
|
---|
287 | QDomDocumentFragmentPrivate( QDomDocumentPrivate*, QDomNodePrivate* parent = 0 );
|
---|
288 | QDomDocumentFragmentPrivate( QDomNodePrivate* n, bool deep );
|
---|
289 | ~QDomDocumentFragmentPrivate();
|
---|
290 |
|
---|
291 | // Reimplemented from QDomNodePrivate
|
---|
292 | QDomNodePrivate* cloneNode( bool deep = TRUE );
|
---|
293 | bool isDocumentFragment() { return TRUE; }
|
---|
294 | QDomNode::NodeType nodeType() const { return QDomNode::DocumentFragmentNode; }
|
---|
295 | };
|
---|
296 |
|
---|
297 | class QDomCharacterDataPrivate : public QDomNodePrivate
|
---|
298 | {
|
---|
299 | public:
|
---|
300 | QDomCharacterDataPrivate( QDomDocumentPrivate*, QDomNodePrivate* parent, const QString& data );
|
---|
301 | QDomCharacterDataPrivate( QDomCharacterDataPrivate* n, bool deep );
|
---|
302 | ~QDomCharacterDataPrivate();
|
---|
303 |
|
---|
304 | uint dataLength() const;
|
---|
305 | QString substringData( unsigned long offset, unsigned long count ) const;
|
---|
306 | void appendData( const QString& arg );
|
---|
307 | void insertData( unsigned long offset, const QString& arg );
|
---|
308 | void deleteData( unsigned long offset, unsigned long count );
|
---|
309 | void replaceData( unsigned long offset, unsigned long count, const QString& arg );
|
---|
310 |
|
---|
311 | // Reimplemented from QDomNodePrivate
|
---|
312 | bool isCharacterData() { return TRUE; }
|
---|
313 | QDomNode::NodeType nodeType() const { return QDomNode::CharacterDataNode; }
|
---|
314 | QDomNodePrivate* cloneNode( bool deep = TRUE );
|
---|
315 |
|
---|
316 | };
|
---|
317 |
|
---|
318 | class QDomTextPrivate : public QDomCharacterDataPrivate
|
---|
319 | {
|
---|
320 | public:
|
---|
321 | QDomTextPrivate( QDomDocumentPrivate*, QDomNodePrivate* parent, const QString& value );
|
---|
322 | QDomTextPrivate( QDomTextPrivate* n, bool deep );
|
---|
323 | ~QDomTextPrivate();
|
---|
324 |
|
---|
325 | QDomTextPrivate* splitText( int offset );
|
---|
326 |
|
---|
327 | // Reimplemented from QDomNodePrivate
|
---|
328 | QDomNodePrivate* cloneNode( bool deep = TRUE );
|
---|
329 | bool isText() { return TRUE; }
|
---|
330 | QDomNode::NodeType nodeType() const { return QDomNode::TextNode; }
|
---|
331 | void save( QTextStream& s, int, int ) const;
|
---|
332 |
|
---|
333 | };
|
---|
334 |
|
---|
335 | class QDomAttrPrivate : public QDomNodePrivate
|
---|
336 | {
|
---|
337 | public:
|
---|
338 | QDomAttrPrivate( QDomDocumentPrivate*, QDomNodePrivate*, const QString& name );
|
---|
339 | QDomAttrPrivate( QDomDocumentPrivate*, QDomNodePrivate*, const QString& nsURI, const QString& qName );
|
---|
340 | QDomAttrPrivate( QDomAttrPrivate* n, bool deep );
|
---|
341 | ~QDomAttrPrivate();
|
---|
342 |
|
---|
343 | bool specified() const;
|
---|
344 |
|
---|
345 | // Reimplemented from QDomNodePrivate
|
---|
346 | void setNodeValue( const QString& v );
|
---|
347 | QDomNodePrivate* cloneNode( bool deep = TRUE );
|
---|
348 | bool isAttr() { return TRUE; }
|
---|
349 | QDomNode::NodeType nodeType() const { return QDomNode::AttributeNode; }
|
---|
350 | void save( QTextStream& s, int, int ) const;
|
---|
351 |
|
---|
352 | // Variables
|
---|
353 | bool m_specified;
|
---|
354 | };
|
---|
355 |
|
---|
356 | class QDomElementPrivate : public QDomNodePrivate
|
---|
357 | {
|
---|
358 | public:
|
---|
359 | QDomElementPrivate( QDomDocumentPrivate*, QDomNodePrivate* parent, const QString& name );
|
---|
360 | QDomElementPrivate( QDomDocumentPrivate*, QDomNodePrivate* parent, const QString& nsURI, const QString& qName );
|
---|
361 | QDomElementPrivate( QDomElementPrivate* n, bool deep );
|
---|
362 | ~QDomElementPrivate();
|
---|
363 |
|
---|
364 | QString attribute( const QString& name, const QString& defValue ) const;
|
---|
365 | QString attributeNS( const QString& nsURI, const QString& localName, const QString& defValue ) const;
|
---|
366 | void setAttribute( const QString& name, const QString& value );
|
---|
367 | void setAttributeNS( const QString& nsURI, const QString& qName, const QString& newValue );
|
---|
368 | void removeAttribute( const QString& name );
|
---|
369 | QDomAttrPrivate* attributeNode( const QString& name);
|
---|
370 | QDomAttrPrivate* attributeNodeNS( const QString& nsURI, const QString& localName );
|
---|
371 | QDomAttrPrivate* setAttributeNode( QDomAttrPrivate* newAttr );
|
---|
372 | QDomAttrPrivate* setAttributeNodeNS( QDomAttrPrivate* newAttr );
|
---|
373 | QDomAttrPrivate* removeAttributeNode( QDomAttrPrivate* oldAttr );
|
---|
374 | bool hasAttribute( const QString& name );
|
---|
375 | bool hasAttributeNS( const QString& nsURI, const QString& localName );
|
---|
376 |
|
---|
377 | QString text();
|
---|
378 |
|
---|
379 | // Reimplemented from QDomNodePrivate
|
---|
380 | QDomNamedNodeMapPrivate* attributes() { return m_attr; }
|
---|
381 | bool hasAttributes() { return ( m_attr->length() > 0 ); }
|
---|
382 | bool isElement() { return TRUE; }
|
---|
383 | QDomNode::NodeType nodeType() const { return QDomNode::ElementNode; }
|
---|
384 | QDomNodePrivate* cloneNode( bool deep = TRUE );
|
---|
385 | void save( QTextStream& s, int, int ) const;
|
---|
386 |
|
---|
387 | // Variables
|
---|
388 | QDomNamedNodeMapPrivate* m_attr;
|
---|
389 | };
|
---|
390 |
|
---|
391 |
|
---|
392 | class QDomCommentPrivate : public QDomCharacterDataPrivate
|
---|
393 | {
|
---|
394 | public:
|
---|
395 | QDomCommentPrivate( QDomDocumentPrivate*, QDomNodePrivate* parent, const QString& value );
|
---|
396 | QDomCommentPrivate( QDomCommentPrivate* n, bool deep );
|
---|
397 | ~QDomCommentPrivate();
|
---|
398 |
|
---|
399 | // Reimplemented from QDomNodePrivate
|
---|
400 | QDomNodePrivate* cloneNode( bool deep = TRUE );
|
---|
401 | bool isComment() { return TRUE; }
|
---|
402 | QDomNode::NodeType nodeType() const { return QDomNode::CommentNode; }
|
---|
403 | void save( QTextStream& s, int, int ) const;
|
---|
404 |
|
---|
405 | };
|
---|
406 |
|
---|
407 | class QDomCDATASectionPrivate : public QDomTextPrivate
|
---|
408 | {
|
---|
409 | public:
|
---|
410 | QDomCDATASectionPrivate( QDomDocumentPrivate*, QDomNodePrivate* parent, const QString& value );
|
---|
411 | QDomCDATASectionPrivate( QDomCDATASectionPrivate* n, bool deep );
|
---|
412 | ~QDomCDATASectionPrivate();
|
---|
413 |
|
---|
414 | // Reimplemented from QDomNodePrivate
|
---|
415 | QDomNodePrivate* cloneNode( bool deep = TRUE );
|
---|
416 | bool isCDATASection() { return TRUE; }
|
---|
417 | QDomNode::NodeType nodeType() const { return QDomNode::CDATASectionNode; }
|
---|
418 | void save( QTextStream& s, int, int ) const;
|
---|
419 |
|
---|
420 | };
|
---|
421 |
|
---|
422 | class QDomNotationPrivate : public QDomNodePrivate
|
---|
423 | {
|
---|
424 | public:
|
---|
425 | QDomNotationPrivate( QDomDocumentPrivate*, QDomNodePrivate* parent, const QString& name,
|
---|
426 | const QString& pub, const QString& sys );
|
---|
427 | QDomNotationPrivate( QDomNotationPrivate* n, bool deep );
|
---|
428 | ~QDomNotationPrivate();
|
---|
429 |
|
---|
430 | // Reimplemented from QDomNodePrivate
|
---|
431 | QDomNodePrivate* cloneNode( bool deep = TRUE );
|
---|
432 | bool isNotation() { return TRUE; }
|
---|
433 | QDomNode::NodeType nodeType() const { return QDomNode::NotationNode; }
|
---|
434 | void save( QTextStream& s, int, int ) const;
|
---|
435 |
|
---|
436 | // Variables
|
---|
437 | QString m_sys;
|
---|
438 | QString m_pub;
|
---|
439 | };
|
---|
440 |
|
---|
441 | class QDomEntityPrivate : public QDomNodePrivate
|
---|
442 | {
|
---|
443 | public:
|
---|
444 | QDomEntityPrivate( QDomDocumentPrivate*, QDomNodePrivate* parent, const QString& name,
|
---|
445 | const QString& pub, const QString& sys, const QString& notation );
|
---|
446 | QDomEntityPrivate( QDomEntityPrivate* n, bool deep );
|
---|
447 | ~QDomEntityPrivate();
|
---|
448 |
|
---|
449 | // Reimplemented from QDomNodePrivate
|
---|
450 | QDomNodePrivate* cloneNode( bool deep = TRUE );
|
---|
451 | bool isEntity() { return TRUE; }
|
---|
452 | QDomNode::NodeType nodeType() const { return QDomNode::EntityNode; }
|
---|
453 | void save( QTextStream& s, int, int ) const;
|
---|
454 |
|
---|
455 | // Variables
|
---|
456 | QString m_sys;
|
---|
457 | QString m_pub;
|
---|
458 | QString m_notationName;
|
---|
459 | };
|
---|
460 |
|
---|
461 | class QDomEntityReferencePrivate : public QDomNodePrivate
|
---|
462 | {
|
---|
463 | public:
|
---|
464 | QDomEntityReferencePrivate( QDomDocumentPrivate*, QDomNodePrivate* parent, const QString& name );
|
---|
465 | QDomEntityReferencePrivate( QDomNodePrivate* n, bool deep );
|
---|
466 | ~QDomEntityReferencePrivate();
|
---|
467 |
|
---|
468 | // Reimplemented from QDomNodePrivate
|
---|
469 | QDomNodePrivate* cloneNode( bool deep = TRUE );
|
---|
470 | bool isEntityReference() { return TRUE; }
|
---|
471 | QDomNode::NodeType nodeType() const { return QDomNode::EntityReferenceNode; }
|
---|
472 | void save( QTextStream& s, int, int ) const;
|
---|
473 | };
|
---|
474 |
|
---|
475 | class QDomProcessingInstructionPrivate : public QDomNodePrivate
|
---|
476 | {
|
---|
477 | public:
|
---|
478 | QDomProcessingInstructionPrivate( QDomDocumentPrivate*, QDomNodePrivate* parent, const QString& target,
|
---|
479 | const QString& data);
|
---|
480 | QDomProcessingInstructionPrivate( QDomProcessingInstructionPrivate* n, bool deep );
|
---|
481 | ~QDomProcessingInstructionPrivate();
|
---|
482 |
|
---|
483 | // Reimplemented from QDomNodePrivate
|
---|
484 | QDomNodePrivate* cloneNode( bool deep = TRUE );
|
---|
485 | bool isProcessingInstruction() { return TRUE; }
|
---|
486 | QDomNode::NodeType nodeType() const { return QDomNode::ProcessingInstructionNode; }
|
---|
487 | void save( QTextStream& s, int, int ) const;
|
---|
488 | };
|
---|
489 |
|
---|
490 | class QDomDocumentPrivate : public QDomNodePrivate
|
---|
491 | {
|
---|
492 | public:
|
---|
493 | QDomDocumentPrivate();
|
---|
494 | QDomDocumentPrivate( const QString& name );
|
---|
495 | QDomDocumentPrivate( QDomDocumentTypePrivate* dt );
|
---|
496 | QDomDocumentPrivate( QDomDocumentPrivate* n, bool deep );
|
---|
497 | ~QDomDocumentPrivate();
|
---|
498 |
|
---|
499 | bool setContent( QXmlInputSource *source, bool namespaceProcessing, QString *errorMsg, int *errorLine, int *errorColumn );
|
---|
500 | bool setContent( QXmlInputSource *source, QXmlReader *reader, QString *errorMsg, int *errorLine, int *errorColumn );
|
---|
501 |
|
---|
502 | // Attributes
|
---|
503 | QDomDocumentTypePrivate* doctype() { return type; };
|
---|
504 | QDomImplementationPrivate* implementation() { return impl; };
|
---|
505 | QDomElementPrivate* documentElement();
|
---|
506 |
|
---|
507 | // Factories
|
---|
508 | QDomElementPrivate* createElement( const QString& tagName );
|
---|
509 | QDomElementPrivate* createElementNS( const QString& nsURI, const QString& qName );
|
---|
510 | QDomDocumentFragmentPrivate* createDocumentFragment();
|
---|
511 | QDomTextPrivate* createTextNode( const QString& data );
|
---|
512 | QDomCommentPrivate* createComment( const QString& data );
|
---|
513 | QDomCDATASectionPrivate* createCDATASection( const QString& data );
|
---|
514 | QDomProcessingInstructionPrivate* createProcessingInstruction( const QString& target, const QString& data );
|
---|
515 | QDomAttrPrivate* createAttribute( const QString& name );
|
---|
516 | QDomAttrPrivate* createAttributeNS( const QString& nsURI, const QString& qName );
|
---|
517 | QDomEntityReferencePrivate* createEntityReference( const QString& name );
|
---|
518 |
|
---|
519 | QDomNodePrivate* importNode( const QDomNodePrivate* importedNode, bool deep );
|
---|
520 |
|
---|
521 | // Reimplemented from QDomNodePrivate
|
---|
522 | QDomNodePrivate* cloneNode( bool deep = TRUE );
|
---|
523 | bool isDocument() { return TRUE; }
|
---|
524 | QDomNode::NodeType nodeType() const { return QDomNode::DocumentNode; }
|
---|
525 | void clear();
|
---|
526 | void save( QTextStream&, int, int ) const;
|
---|
527 |
|
---|
528 | // Variables
|
---|
529 | QDomImplementationPrivate* impl;
|
---|
530 | QDomDocumentTypePrivate* type;
|
---|
531 | };
|
---|
532 |
|
---|
533 | /**************************************************************
|
---|
534 | *
|
---|
535 | * QDomHandler
|
---|
536 | *
|
---|
537 | **************************************************************/
|
---|
538 |
|
---|
539 | class QDomHandler : public QXmlDefaultHandler
|
---|
540 | {
|
---|
541 | public:
|
---|
542 | QDomHandler( QDomDocumentPrivate* d, bool namespaceProcessing );
|
---|
543 | ~QDomHandler();
|
---|
544 |
|
---|
545 | // content handler
|
---|
546 | bool endDocument();
|
---|
547 | bool startElement( const QString& nsURI, const QString& localName, const QString& qName, const QXmlAttributes& atts );
|
---|
548 | bool endElement( const QString& nsURI, const QString& localName, const QString& qName );
|
---|
549 | bool characters( const QString& ch );
|
---|
550 | bool processingInstruction( const QString& target, const QString& data );
|
---|
551 | bool skippedEntity( const QString& name );
|
---|
552 |
|
---|
553 | // error handler
|
---|
554 | bool fatalError( const QXmlParseException& exception );
|
---|
555 |
|
---|
556 | // lexical handler
|
---|
557 | bool startCDATA();
|
---|
558 | bool endCDATA();
|
---|
559 | bool startEntity( const QString & );
|
---|
560 | bool endEntity( const QString & );
|
---|
561 | bool startDTD( const QString& name, const QString& publicId, const QString& systemId );
|
---|
562 | bool comment( const QString& ch );
|
---|
563 |
|
---|
564 | // decl handler
|
---|
565 | bool externalEntityDecl( const QString &name, const QString &publicId, const QString &systemId ) ;
|
---|
566 |
|
---|
567 | // DTD handler
|
---|
568 | bool notationDecl( const QString & name, const QString & publicId, const QString & systemId );
|
---|
569 | bool unparsedEntityDecl( const QString &name, const QString &publicId, const QString &systemId, const QString ¬ationName ) ;
|
---|
570 |
|
---|
571 | QString errorMsg;
|
---|
572 | int errorLine;
|
---|
573 | int errorColumn;
|
---|
574 |
|
---|
575 | private:
|
---|
576 | QDomDocumentPrivate *doc;
|
---|
577 | QDomNodePrivate *node;
|
---|
578 | QString entityName;
|
---|
579 | bool cdata;
|
---|
580 | bool nsProcessing;
|
---|
581 | };
|
---|
582 |
|
---|
583 | /**************************************************************
|
---|
584 | *
|
---|
585 | * QDomImplementationPrivate
|
---|
586 | *
|
---|
587 | **************************************************************/
|
---|
588 |
|
---|
589 | QDomImplementationPrivate::QDomImplementationPrivate()
|
---|
590 | {
|
---|
591 | }
|
---|
592 |
|
---|
593 | QDomImplementationPrivate::~QDomImplementationPrivate()
|
---|
594 | {
|
---|
595 | }
|
---|
596 |
|
---|
597 | QDomImplementationPrivate* QDomImplementationPrivate::clone()
|
---|
598 | {
|
---|
599 | QDomImplementationPrivate* p = new QDomImplementationPrivate;
|
---|
600 | // We are not interested in this node
|
---|
601 | p->deref();
|
---|
602 | return p;
|
---|
603 | }
|
---|
604 |
|
---|
605 | /**************************************************************
|
---|
606 | *
|
---|
607 | * QDomImplementation
|
---|
608 | *
|
---|
609 | **************************************************************/
|
---|
610 |
|
---|
611 | /*!
|
---|
612 | \class QDomImplementation qdom.h
|
---|
613 | \reentrant
|
---|
614 | \brief The QDomImplementation class provides information about the
|
---|
615 | features of the DOM implementation.
|
---|
616 | \if defined(commercial)
|
---|
617 | It is part of the <a href="commercialeditions.html">Qt Enterprise Edition</a>.
|
---|
618 | \endif
|
---|
619 |
|
---|
620 | \module XML
|
---|
621 | \ingroup xml-tools
|
---|
622 |
|
---|
623 | This class describes the features that are supported by the DOM
|
---|
624 | implementation. Currently the XML subset of DOM Level 1 and DOM
|
---|
625 | Level 2 Core are supported.
|
---|
626 |
|
---|
627 | Normally you will use the function QDomDocument::implementation()
|
---|
628 | to get the implementation object.
|
---|
629 |
|
---|
630 | You can create a new document type with createDocumentType() and a
|
---|
631 | new document with createDocument().
|
---|
632 |
|
---|
633 | For further information about the Document Object Model see \link
|
---|
634 | http://www.w3.org/TR/REC-DOM-Level-1/\endlink and \link
|
---|
635 | http://www.w3.org/TR/DOM-Level-2-Core/\endlink. For a more general
|
---|
636 | introduction of the DOM implementation see the QDomDocument
|
---|
637 | documentation.
|
---|
638 |
|
---|
639 | \sa hasFeature()
|
---|
640 | */
|
---|
641 |
|
---|
642 | /*!
|
---|
643 | Constructs a QDomImplementation object.
|
---|
644 | */
|
---|
645 | QDomImplementation::QDomImplementation()
|
---|
646 | {
|
---|
647 | impl = 0;
|
---|
648 | }
|
---|
649 |
|
---|
650 | /*!
|
---|
651 | Constructs a copy of \a x.
|
---|
652 | */
|
---|
653 | QDomImplementation::QDomImplementation( const QDomImplementation& x )
|
---|
654 | {
|
---|
655 | impl = x.impl;
|
---|
656 | if ( impl )
|
---|
657 | impl->ref();
|
---|
658 | }
|
---|
659 |
|
---|
660 | QDomImplementation::QDomImplementation( QDomImplementationPrivate* p )
|
---|
661 | {
|
---|
662 | // We want to be co-owners, so increase the reference count
|
---|
663 | impl = p;
|
---|
664 | if (impl)
|
---|
665 | impl->ref();
|
---|
666 | }
|
---|
667 |
|
---|
668 | /*!
|
---|
669 | Assigns \a x to this DOM implementation.
|
---|
670 | */
|
---|
671 | QDomImplementation& QDomImplementation::operator= ( const QDomImplementation& x )
|
---|
672 | {
|
---|
673 | if ( x.impl )
|
---|
674 | x.impl->ref(); // avoid x=x
|
---|
675 | if ( impl && impl->deref() )
|
---|
676 | delete impl;
|
---|
677 | impl = x.impl;
|
---|
678 |
|
---|
679 | return *this;
|
---|
680 | }
|
---|
681 |
|
---|
682 | /*!
|
---|
683 | Returns TRUE if \a x and this DOM implementation object were
|
---|
684 | created from the same QDomDocument; otherwise returns FALSE.
|
---|
685 | */
|
---|
686 | bool QDomImplementation::operator==( const QDomImplementation& x ) const
|
---|
687 | {
|
---|
688 | return ( impl == x.impl );
|
---|
689 | }
|
---|
690 |
|
---|
691 | /*!
|
---|
692 | Returns TRUE if \a x and this DOM implementation object were
|
---|
693 | created from different QDomDocuments; otherwise returns FALSE.
|
---|
694 | */
|
---|
695 | bool QDomImplementation::operator!=( const QDomImplementation& x ) const
|
---|
696 | {
|
---|
697 | return ( impl != x.impl );
|
---|
698 | }
|
---|
699 |
|
---|
700 | /*!
|
---|
701 | Destroys the object and frees its resources.
|
---|
702 | */
|
---|
703 | QDomImplementation::~QDomImplementation()
|
---|
704 | {
|
---|
705 | if ( impl && impl->deref() )
|
---|
706 | delete impl;
|
---|
707 | }
|
---|
708 |
|
---|
709 | /*!
|
---|
710 | The function returns TRUE if QDom implements the requested \a
|
---|
711 | version of a \a feature; otherwise returns FALSE.
|
---|
712 |
|
---|
713 | The currently supported features and their versions:
|
---|
714 | \table
|
---|
715 | \header \i Feature \i Version
|
---|
716 | \row \i XML \i 1.0
|
---|
717 | \endtable
|
---|
718 | */
|
---|
719 | bool QDomImplementation::hasFeature( const QString& feature, const QString& version )
|
---|
720 | {
|
---|
721 | if ( feature == "XML" ) {
|
---|
722 | if ( version.isEmpty() || version == "1.0" ) {
|
---|
723 | return TRUE;
|
---|
724 | }
|
---|
725 | }
|
---|
726 | // ### add DOM level 2 features
|
---|
727 | return FALSE;
|
---|
728 | }
|
---|
729 |
|
---|
730 | /*!
|
---|
731 | Creates a document type node for the name \a qName.
|
---|
732 |
|
---|
733 | \a publicId specifies the public identifier of the external
|
---|
734 | subset. If you specify QString::null as the \a publicId, this
|
---|
735 | means that the document type has no public identifier.
|
---|
736 |
|
---|
737 | \a systemId specifies the system identifier of the external
|
---|
738 | subset. If you specify QString::null as the \a systemId, this
|
---|
739 | means that the document type has no system identifier.
|
---|
740 |
|
---|
741 | Since you cannot have a public identifier without a system
|
---|
742 | identifier, the public identifier is set to QString::null if there
|
---|
743 | is no system identifier.
|
---|
744 |
|
---|
745 | DOM level 2 does not support any other document type declaration
|
---|
746 | features.
|
---|
747 |
|
---|
748 | The only way you can use a document type that was created this
|
---|
749 | way, is in combination with the createDocument() function to
|
---|
750 | create a QDomDocument with this document type.
|
---|
751 |
|
---|
752 | \sa createDocument();
|
---|
753 | */
|
---|
754 | QDomDocumentType QDomImplementation::createDocumentType( const QString& qName, const QString& publicId, const QString& systemId )
|
---|
755 | {
|
---|
756 | QDomDocumentTypePrivate *dt = new QDomDocumentTypePrivate( 0 );
|
---|
757 | dt->name = qName;
|
---|
758 | if ( systemId.isNull() ) {
|
---|
759 | dt->publicId = QString::null;
|
---|
760 | dt->systemId = QString::null;
|
---|
761 | } else {
|
---|
762 | dt->publicId = publicId;
|
---|
763 | dt->systemId = systemId;
|
---|
764 | }
|
---|
765 | return QDomDocumentType( dt );
|
---|
766 | }
|
---|
767 |
|
---|
768 | /*!
|
---|
769 | Creates a DOM document with the document type \a doctype. This
|
---|
770 | function also adds a root element node with the qualified name \a
|
---|
771 | qName and the namespace URI \a nsURI.
|
---|
772 | */
|
---|
773 | QDomDocument QDomImplementation::createDocument( const QString& nsURI, const QString& qName, const QDomDocumentType& doctype )
|
---|
774 | {
|
---|
775 | QDomDocument doc( doctype );
|
---|
776 | QDomElement root = doc.createElementNS( nsURI, qName );
|
---|
777 | doc.appendChild( root );
|
---|
778 | return doc;
|
---|
779 | }
|
---|
780 |
|
---|
781 | /*!
|
---|
782 | Returns FALSE if the object was created by
|
---|
783 | QDomDocument::implementation(); otherwise returns TRUE.
|
---|
784 | */
|
---|
785 | bool QDomImplementation::isNull()
|
---|
786 | {
|
---|
787 | return ( impl == 0 );
|
---|
788 | }
|
---|
789 |
|
---|
790 | /**************************************************************
|
---|
791 | *
|
---|
792 | * QDomNodeListPrivate
|
---|
793 | *
|
---|
794 | **************************************************************/
|
---|
795 |
|
---|
796 | QDomNodeListPrivate::QDomNodeListPrivate( QDomNodePrivate* n_impl )
|
---|
797 | {
|
---|
798 | node_impl = n_impl;
|
---|
799 | if ( node_impl )
|
---|
800 | node_impl->ref();
|
---|
801 | timestamp = -1;
|
---|
802 | }
|
---|
803 |
|
---|
804 | QDomNodeListPrivate::QDomNodeListPrivate( QDomNodePrivate* n_impl, const QString& name )
|
---|
805 | {
|
---|
806 | node_impl = n_impl;
|
---|
807 | if ( node_impl )
|
---|
808 | node_impl->ref();
|
---|
809 | tagname = name;
|
---|
810 | timestamp = -1;
|
---|
811 | }
|
---|
812 |
|
---|
813 | QDomNodeListPrivate::QDomNodeListPrivate( QDomNodePrivate* n_impl, const QString& _nsURI, const QString& localName )
|
---|
814 | {
|
---|
815 | node_impl = n_impl;
|
---|
816 | if ( node_impl )
|
---|
817 | node_impl->ref();
|
---|
818 | tagname = localName;
|
---|
819 | nsURI = _nsURI;
|
---|
820 | timestamp = -1;
|
---|
821 | }
|
---|
822 |
|
---|
823 | QDomNodeListPrivate::~QDomNodeListPrivate()
|
---|
824 | {
|
---|
825 | if ( node_impl && node_impl->deref() )
|
---|
826 | delete node_impl;
|
---|
827 | }
|
---|
828 |
|
---|
829 | bool QDomNodeListPrivate::operator== ( const QDomNodeListPrivate& other ) const
|
---|
830 | {
|
---|
831 | return ( node_impl == other.node_impl ) && ( tagname == other.tagname ) ;
|
---|
832 | }
|
---|
833 |
|
---|
834 | bool QDomNodeListPrivate::operator!= ( const QDomNodeListPrivate& other ) const
|
---|
835 | {
|
---|
836 | return ( node_impl != other.node_impl ) || ( tagname != other.tagname ) ;
|
---|
837 | }
|
---|
838 |
|
---|
839 | void QDomNodeListPrivate::createList()
|
---|
840 | {
|
---|
841 | if ( !node_impl )
|
---|
842 | return;
|
---|
843 | timestamp = qt_nodeListTime;
|
---|
844 | QDomNodePrivate* p = node_impl->first;
|
---|
845 |
|
---|
846 | list.clear();
|
---|
847 | if ( tagname.isNull() ) {
|
---|
848 | while ( p ) {
|
---|
849 | list.append( p );
|
---|
850 | p = p->next;
|
---|
851 | }
|
---|
852 | } else if ( nsURI.isNull() ) {
|
---|
853 | while ( p && p != node_impl ) {
|
---|
854 | if ( p->isElement() && p->nodeName() == tagname ) {
|
---|
855 | list.append( p );
|
---|
856 | }
|
---|
857 | if ( p->first )
|
---|
858 | p = p->first;
|
---|
859 | else if ( p->next )
|
---|
860 | p = p->next;
|
---|
861 | else {
|
---|
862 | p = p->parent();
|
---|
863 | while ( p && p != node_impl && !p->next )
|
---|
864 | p = p->parent();
|
---|
865 | if ( p && p != node_impl )
|
---|
866 | p = p->next;
|
---|
867 | }
|
---|
868 | }
|
---|
869 | } else {
|
---|
870 | while ( p && p != node_impl ) {
|
---|
871 | if ( p->isElement() && p->name==tagname && p->namespaceURI==nsURI ) {
|
---|
872 | list.append( p );
|
---|
873 | }
|
---|
874 | if ( p->first )
|
---|
875 | p = p->first;
|
---|
876 | else if ( p->next )
|
---|
877 | p = p->next;
|
---|
878 | else {
|
---|
879 | p = p->parent();
|
---|
880 | while ( p && p != node_impl && !p->next )
|
---|
881 | p = p->parent();
|
---|
882 | if ( p && p != node_impl )
|
---|
883 | p = p->next;
|
---|
884 | }
|
---|
885 | }
|
---|
886 | }
|
---|
887 | }
|
---|
888 |
|
---|
889 | QDomNodePrivate* QDomNodeListPrivate::item( int index )
|
---|
890 | {
|
---|
891 | if ( !node_impl )
|
---|
892 | return 0;
|
---|
893 | if ( timestamp < qt_nodeListTime )
|
---|
894 | createList();
|
---|
895 | return list.at( index );
|
---|
896 | }
|
---|
897 |
|
---|
898 | uint QDomNodeListPrivate::length() const
|
---|
899 | {
|
---|
900 | if ( !node_impl )
|
---|
901 | return 0;
|
---|
902 | if ( timestamp < qt_nodeListTime ) {
|
---|
903 | QDomNodeListPrivate *that = (QDomNodeListPrivate*)this;
|
---|
904 | that->createList();
|
---|
905 | }
|
---|
906 | return list.count();
|
---|
907 | }
|
---|
908 |
|
---|
909 | /**************************************************************
|
---|
910 | *
|
---|
911 | * QDomNodeList
|
---|
912 | *
|
---|
913 | **************************************************************/
|
---|
914 |
|
---|
915 | /*!
|
---|
916 | \class QDomNodeList qdom.h
|
---|
917 | \reentrant
|
---|
918 | \brief The QDomNodeList class is a list of QDomNode objects.
|
---|
919 | \if defined(commercial)
|
---|
920 | It is part of the <a href="commercialeditions.html">Qt Enterprise Edition</a>.
|
---|
921 | \endif
|
---|
922 |
|
---|
923 | \module XML
|
---|
924 | \ingroup xml-tools
|
---|
925 |
|
---|
926 | Lists can be obtained by QDomDocument::elementsByTagName() and
|
---|
927 | QDomNode::childNodes(). The Document Object Model (DOM) requires
|
---|
928 | these lists to be "live": whenever you change the underlying
|
---|
929 | document, the contents of the list will get updated.
|
---|
930 |
|
---|
931 | You can get a particular node from the list with item(). The
|
---|
932 | number of items in the list is returned by count() (and by
|
---|
933 | length()).
|
---|
934 |
|
---|
935 | For further information about the Document Object Model see \link
|
---|
936 | http://www.w3.org/TR/REC-DOM-Level-1/\endlink and \link
|
---|
937 | http://www.w3.org/TR/DOM-Level-2-Core/\endlink. For a more general
|
---|
938 | introduction of the DOM implementation see the QDomDocument
|
---|
939 | documentation.
|
---|
940 |
|
---|
941 | \sa QDomNode::childNodes() QDomDocument::elementsByTagName()
|
---|
942 | */
|
---|
943 |
|
---|
944 | /*!
|
---|
945 | Creates an empty node list.
|
---|
946 | */
|
---|
947 | QDomNodeList::QDomNodeList()
|
---|
948 | {
|
---|
949 | impl = 0;
|
---|
950 | }
|
---|
951 |
|
---|
952 | QDomNodeList::QDomNodeList( QDomNodeListPrivate* p )
|
---|
953 | {
|
---|
954 | impl = p;
|
---|
955 | }
|
---|
956 |
|
---|
957 | /*!
|
---|
958 | Constructs a copy of \a n.
|
---|
959 | */
|
---|
960 | QDomNodeList::QDomNodeList( const QDomNodeList& n )
|
---|
961 | {
|
---|
962 | impl = n.impl;
|
---|
963 | if ( impl )
|
---|
964 | impl->ref();
|
---|
965 | }
|
---|
966 |
|
---|
967 | /*!
|
---|
968 | Assigns \a n to this node list.
|
---|
969 | */
|
---|
970 | QDomNodeList& QDomNodeList::operator= ( const QDomNodeList& n )
|
---|
971 | {
|
---|
972 | if ( n.impl )
|
---|
973 | n.impl->ref();
|
---|
974 | if ( impl && impl->deref() )
|
---|
975 | delete impl;
|
---|
976 | impl = n.impl;
|
---|
977 |
|
---|
978 | return *this;
|
---|
979 | }
|
---|
980 |
|
---|
981 | /*!
|
---|
982 | Returns TRUE if the node list \a n and this node list are equal;
|
---|
983 | otherwise returns FALSE.
|
---|
984 | */
|
---|
985 | bool QDomNodeList::operator== ( const QDomNodeList& n ) const
|
---|
986 | {
|
---|
987 | if ( impl == n.impl )
|
---|
988 | return TRUE;
|
---|
989 | if ( !impl || !n.impl )
|
---|
990 | return FALSE;
|
---|
991 | return (*impl == *n.impl);
|
---|
992 | }
|
---|
993 |
|
---|
994 | /*!
|
---|
995 | Returns TRUE the node list \a n and this node list are not equal;
|
---|
996 | otherwise returns FALSE.
|
---|
997 | */
|
---|
998 | bool QDomNodeList::operator!= ( const QDomNodeList& n ) const
|
---|
999 | {
|
---|
1000 | return !operator==(n);
|
---|
1001 | }
|
---|
1002 |
|
---|
1003 | /*!
|
---|
1004 | Destroys the object and frees its resources.
|
---|
1005 | */
|
---|
1006 | QDomNodeList::~QDomNodeList()
|
---|
1007 | {
|
---|
1008 | if ( impl && impl->deref() )
|
---|
1009 | delete impl;
|
---|
1010 | }
|
---|
1011 |
|
---|
1012 | /*!
|
---|
1013 | Returns the node at position \a index.
|
---|
1014 |
|
---|
1015 | If \a index is negative or if \a index >= length() then a null
|
---|
1016 | node is returned (i.e. a node for which QDomNode::isNull() returns
|
---|
1017 | TRUE).
|
---|
1018 |
|
---|
1019 | \sa count()
|
---|
1020 | */
|
---|
1021 | QDomNode QDomNodeList::item( int index ) const
|
---|
1022 | {
|
---|
1023 | if ( !impl )
|
---|
1024 | return QDomNode();
|
---|
1025 |
|
---|
1026 | return QDomNode( impl->item( index ) );
|
---|
1027 | }
|
---|
1028 |
|
---|
1029 | /*!
|
---|
1030 | Returns the number of nodes in the list.
|
---|
1031 |
|
---|
1032 | This function is the same as count().
|
---|
1033 | */
|
---|
1034 | uint QDomNodeList::length() const
|
---|
1035 | {
|
---|
1036 | if ( !impl )
|
---|
1037 | return 0;
|
---|
1038 | return impl->length();
|
---|
1039 | }
|
---|
1040 |
|
---|
1041 | /*!
|
---|
1042 | \fn uint QDomNodeList::count() const
|
---|
1043 |
|
---|
1044 | Returns the number of nodes in the list.
|
---|
1045 |
|
---|
1046 | This function is the same as length().
|
---|
1047 | */
|
---|
1048 |
|
---|
1049 |
|
---|
1050 | /**************************************************************
|
---|
1051 | *
|
---|
1052 | * QDomNodePrivate
|
---|
1053 | *
|
---|
1054 | **************************************************************/
|
---|
1055 |
|
---|
1056 | inline void QDomNodePrivate::setOwnerDocument( QDomDocumentPrivate* doc )
|
---|
1057 | {
|
---|
1058 | ownerNode = doc;
|
---|
1059 | hasParent = FALSE;
|
---|
1060 | }
|
---|
1061 |
|
---|
1062 | QDomNodePrivate::QDomNodePrivate( QDomDocumentPrivate* doc, QDomNodePrivate *par )
|
---|
1063 | {
|
---|
1064 | if ( par )
|
---|
1065 | setParent( par );
|
---|
1066 | else
|
---|
1067 | setOwnerDocument( doc );
|
---|
1068 | prev = 0;
|
---|
1069 | next = 0;
|
---|
1070 | first = 0;
|
---|
1071 | last = 0;
|
---|
1072 | createdWithDom1Interface = TRUE;
|
---|
1073 | }
|
---|
1074 |
|
---|
1075 | QDomNodePrivate::QDomNodePrivate( QDomNodePrivate* n, bool deep )
|
---|
1076 | {
|
---|
1077 | setOwnerDocument( n->ownerDocument() );
|
---|
1078 | prev = 0;
|
---|
1079 | next = 0;
|
---|
1080 | first = 0;
|
---|
1081 | last = 0;
|
---|
1082 |
|
---|
1083 | name = n->name;
|
---|
1084 | value = n->value;
|
---|
1085 | prefix = n->prefix;
|
---|
1086 | namespaceURI = n->namespaceURI;
|
---|
1087 | createdWithDom1Interface = n->createdWithDom1Interface;
|
---|
1088 |
|
---|
1089 | if ( !deep )
|
---|
1090 | return;
|
---|
1091 |
|
---|
1092 | for ( QDomNodePrivate* x = n->first; x; x = x->next )
|
---|
1093 | appendChild( x->cloneNode( TRUE ) );
|
---|
1094 | }
|
---|
1095 |
|
---|
1096 | QDomNodePrivate::~QDomNodePrivate()
|
---|
1097 | {
|
---|
1098 | QDomNodePrivate* p = first;
|
---|
1099 | QDomNodePrivate* n;
|
---|
1100 |
|
---|
1101 | while ( p ) {
|
---|
1102 | n = p->next;
|
---|
1103 | if ( p->deref() )
|
---|
1104 | delete p;
|
---|
1105 | else
|
---|
1106 | p->setNoParent();
|
---|
1107 | p = n;
|
---|
1108 | }
|
---|
1109 |
|
---|
1110 | first = 0;
|
---|
1111 | last = 0;
|
---|
1112 | }
|
---|
1113 |
|
---|
1114 | void QDomNodePrivate::clear()
|
---|
1115 | {
|
---|
1116 | QDomNodePrivate* p = first;
|
---|
1117 | QDomNodePrivate* n;
|
---|
1118 |
|
---|
1119 | while ( p ) {
|
---|
1120 | n = p->next;
|
---|
1121 | if ( p->deref() )
|
---|
1122 | delete p;
|
---|
1123 | p = n;
|
---|
1124 | }
|
---|
1125 |
|
---|
1126 | first = 0;
|
---|
1127 | last = 0;
|
---|
1128 | }
|
---|
1129 |
|
---|
1130 | QDomNodePrivate* QDomNodePrivate::namedItem( const QString& n )
|
---|
1131 | {
|
---|
1132 | QDomNodePrivate* p = first;
|
---|
1133 | while ( p ) {
|
---|
1134 | if ( p->nodeName() == n )
|
---|
1135 | return p;
|
---|
1136 | p = p->next;
|
---|
1137 | }
|
---|
1138 |
|
---|
1139 | return 0;
|
---|
1140 | }
|
---|
1141 |
|
---|
1142 | QDomNamedNodeMapPrivate* QDomNodePrivate::attributes()
|
---|
1143 | {
|
---|
1144 | return 0;
|
---|
1145 | }
|
---|
1146 |
|
---|
1147 | QDomNodePrivate* QDomNodePrivate::insertBefore( QDomNodePrivate* newChild, QDomNodePrivate* refChild )
|
---|
1148 | {
|
---|
1149 | // Error check
|
---|
1150 | if ( !newChild )
|
---|
1151 | return 0;
|
---|
1152 |
|
---|
1153 | // Error check
|
---|
1154 | if ( newChild == refChild )
|
---|
1155 | return 0;
|
---|
1156 |
|
---|
1157 | // Error check
|
---|
1158 | if ( refChild && refChild->parent() != this )
|
---|
1159 | return 0;
|
---|
1160 |
|
---|
1161 | // "mark lists as dirty"
|
---|
1162 | qt_nodeListTime++;
|
---|
1163 |
|
---|
1164 | // Special handling for inserting a fragment. We just insert
|
---|
1165 | // all elements of the fragment instead of the fragment itself.
|
---|
1166 | if ( newChild->isDocumentFragment() ) {
|
---|
1167 | // Fragment is empty ?
|
---|
1168 | if ( newChild->first == 0 )
|
---|
1169 | return newChild;
|
---|
1170 |
|
---|
1171 | // New parent
|
---|
1172 | QDomNodePrivate* n = newChild->first;
|
---|
1173 | while ( n ) {
|
---|
1174 | n->setParent( this );
|
---|
1175 | n = n->next;
|
---|
1176 | }
|
---|
1177 |
|
---|
1178 | // Insert at the beginning ?
|
---|
1179 | if ( !refChild || refChild->prev == 0 ) {
|
---|
1180 | if ( first )
|
---|
1181 | first->prev = newChild->last;
|
---|
1182 | newChild->last->next = first;
|
---|
1183 | if ( !last )
|
---|
1184 | last = newChild->last;
|
---|
1185 | first = newChild->first;
|
---|
1186 | } else {
|
---|
1187 | // Insert in the middle
|
---|
1188 | newChild->last->next = refChild;
|
---|
1189 | newChild->first->prev = refChild->prev;
|
---|
1190 | refChild->prev->next = newChild->first;
|
---|
1191 | refChild->prev = newChild->last;
|
---|
1192 | }
|
---|
1193 |
|
---|
1194 | // No need to increase the reference since QDomDocumentFragment
|
---|
1195 | // does not decrease the reference.
|
---|
1196 |
|
---|
1197 | // Remove the nodes from the fragment
|
---|
1198 | newChild->first = 0;
|
---|
1199 | newChild->last = 0;
|
---|
1200 | return newChild;
|
---|
1201 | }
|
---|
1202 |
|
---|
1203 | // No more errors can occur now, so we take
|
---|
1204 | // ownership of the node.
|
---|
1205 | newChild->ref();
|
---|
1206 |
|
---|
1207 | if ( newChild->parent() )
|
---|
1208 | newChild->parent()->removeChild( newChild );
|
---|
1209 |
|
---|
1210 | newChild->setParent( this );
|
---|
1211 |
|
---|
1212 | if ( !refChild ) {
|
---|
1213 | if ( first )
|
---|
1214 | first->prev = newChild;
|
---|
1215 | newChild->next = first;
|
---|
1216 | if ( !last )
|
---|
1217 | last = newChild;
|
---|
1218 | first = newChild;
|
---|
1219 | return newChild;
|
---|
1220 | }
|
---|
1221 |
|
---|
1222 | if ( refChild->prev == 0 ) {
|
---|
1223 | if ( first )
|
---|
1224 | first->prev = newChild;
|
---|
1225 | newChild->next = first;
|
---|
1226 | if ( !last )
|
---|
1227 | last = newChild;
|
---|
1228 | first = newChild;
|
---|
1229 | return newChild;
|
---|
1230 | }
|
---|
1231 |
|
---|
1232 | newChild->next = refChild;
|
---|
1233 | newChild->prev = refChild->prev;
|
---|
1234 | refChild->prev->next = newChild;
|
---|
1235 | refChild->prev = newChild;
|
---|
1236 |
|
---|
1237 | return newChild;
|
---|
1238 | }
|
---|
1239 |
|
---|
1240 | QDomNodePrivate* QDomNodePrivate::insertAfter( QDomNodePrivate* newChild, QDomNodePrivate* refChild )
|
---|
1241 | {
|
---|
1242 | // Error check
|
---|
1243 | if ( !newChild )
|
---|
1244 | return 0;
|
---|
1245 |
|
---|
1246 | // Error check
|
---|
1247 | if ( newChild == refChild )
|
---|
1248 | return 0;
|
---|
1249 |
|
---|
1250 | // Error check
|
---|
1251 | if ( refChild && refChild->parent() != this )
|
---|
1252 | return 0;
|
---|
1253 |
|
---|
1254 | // "mark lists as dirty"
|
---|
1255 | qt_nodeListTime++;
|
---|
1256 |
|
---|
1257 | // Special handling for inserting a fragment. We just insert
|
---|
1258 | // all elements of the fragment instead of the fragment itself.
|
---|
1259 | if ( newChild->isDocumentFragment() ) {
|
---|
1260 | // Fragment is empty ?
|
---|
1261 | if ( newChild->first == 0 )
|
---|
1262 | return newChild;
|
---|
1263 |
|
---|
1264 | // New parent
|
---|
1265 | QDomNodePrivate* n = newChild->first;
|
---|
1266 | while ( n ) {
|
---|
1267 | n->setParent( this );
|
---|
1268 | n = n->next;
|
---|
1269 | }
|
---|
1270 |
|
---|
1271 | // Insert at the end
|
---|
1272 | if ( !refChild || refChild->next == 0 ) {
|
---|
1273 | if ( last )
|
---|
1274 | last->next = newChild->first;
|
---|
1275 | newChild->first->prev = last;
|
---|
1276 | if ( !first )
|
---|
1277 | first = newChild->first;
|
---|
1278 | last = newChild->last;
|
---|
1279 | } else { // Insert in the middle
|
---|
1280 | newChild->first->prev = refChild;
|
---|
1281 | newChild->last->next = refChild->next;
|
---|
1282 | refChild->next->prev = newChild->last;
|
---|
1283 | refChild->next = newChild->first;
|
---|
1284 | }
|
---|
1285 |
|
---|
1286 | // No need to increase the reference since QDomDocumentFragment
|
---|
1287 | // does not decrease the reference.
|
---|
1288 |
|
---|
1289 | // Remove the nodes from the fragment
|
---|
1290 | newChild->first = 0;
|
---|
1291 | newChild->last = 0;
|
---|
1292 | return newChild;
|
---|
1293 | }
|
---|
1294 |
|
---|
1295 | // Release new node from its current parent
|
---|
1296 | if ( newChild->parent() )
|
---|
1297 | newChild->parent()->removeChild( newChild );
|
---|
1298 |
|
---|
1299 | // No more errors can occur now, so we take
|
---|
1300 | // ownership of the node
|
---|
1301 | newChild->ref();
|
---|
1302 |
|
---|
1303 | newChild->setParent( this );
|
---|
1304 |
|
---|
1305 | // Insert at the end
|
---|
1306 | if ( !refChild ) {
|
---|
1307 | if ( last )
|
---|
1308 | last->next = newChild;
|
---|
1309 | newChild->prev = last;
|
---|
1310 | if ( !first )
|
---|
1311 | first = newChild;
|
---|
1312 | last = newChild;
|
---|
1313 | return newChild;
|
---|
1314 | }
|
---|
1315 |
|
---|
1316 | if ( refChild->next == 0 ) {
|
---|
1317 | if ( last )
|
---|
1318 | last->next = newChild;
|
---|
1319 | newChild->prev = last;
|
---|
1320 | if ( !first )
|
---|
1321 | first = newChild;
|
---|
1322 | last = newChild;
|
---|
1323 | return newChild;
|
---|
1324 | }
|
---|
1325 |
|
---|
1326 | newChild->prev = refChild;
|
---|
1327 | newChild->next = refChild->next;
|
---|
1328 | refChild->next->prev = newChild;
|
---|
1329 | refChild->next = newChild;
|
---|
1330 |
|
---|
1331 | return newChild;
|
---|
1332 | }
|
---|
1333 |
|
---|
1334 | QDomNodePrivate* QDomNodePrivate::replaceChild( QDomNodePrivate* newChild, QDomNodePrivate* oldChild )
|
---|
1335 | {
|
---|
1336 | if ( oldChild->parent() != this )
|
---|
1337 | return 0;
|
---|
1338 | if ( !newChild || !oldChild )
|
---|
1339 | return 0;
|
---|
1340 | if ( newChild == oldChild )
|
---|
1341 | return 0;
|
---|
1342 |
|
---|
1343 | // mark lists as dirty
|
---|
1344 | qt_nodeListTime++;
|
---|
1345 |
|
---|
1346 | // Special handling for inserting a fragment. We just insert
|
---|
1347 | // all elements of the fragment instead of the fragment itself.
|
---|
1348 | if ( newChild->isDocumentFragment() ) {
|
---|
1349 | // Fragment is empty ?
|
---|
1350 | if ( newChild->first == 0 )
|
---|
1351 | return newChild;
|
---|
1352 |
|
---|
1353 | // New parent
|
---|
1354 | QDomNodePrivate* n = newChild->first;
|
---|
1355 | while ( n ) {
|
---|
1356 | n->setParent( this );
|
---|
1357 | n = n->next;
|
---|
1358 | }
|
---|
1359 |
|
---|
1360 |
|
---|
1361 | if ( oldChild->next )
|
---|
1362 | oldChild->next->prev = newChild->last;
|
---|
1363 | if ( oldChild->prev )
|
---|
1364 | oldChild->prev->next = newChild->first;
|
---|
1365 |
|
---|
1366 | newChild->last->next = oldChild->next;
|
---|
1367 | newChild->first->prev = oldChild->prev;
|
---|
1368 |
|
---|
1369 | if ( first == oldChild )
|
---|
1370 | first = newChild->first;
|
---|
1371 | if ( last == oldChild )
|
---|
1372 | last = newChild->last;
|
---|
1373 |
|
---|
1374 | oldChild->setNoParent();
|
---|
1375 | oldChild->next = 0;
|
---|
1376 | oldChild->prev = 0;
|
---|
1377 |
|
---|
1378 | // No need to increase the reference since QDomDocumentFragment
|
---|
1379 | // does not decrease the reference.
|
---|
1380 |
|
---|
1381 | // Remove the nodes from the fragment
|
---|
1382 | newChild->first = 0;
|
---|
1383 | newChild->last = 0;
|
---|
1384 |
|
---|
1385 | // We are no longer interested in the old node
|
---|
1386 | if ( oldChild ) oldChild->deref();
|
---|
1387 |
|
---|
1388 | return oldChild;
|
---|
1389 | }
|
---|
1390 |
|
---|
1391 | // No more errors can occur now, so we take
|
---|
1392 | // ownership of the node
|
---|
1393 | newChild->ref();
|
---|
1394 |
|
---|
1395 | // Release new node from its current parent
|
---|
1396 | if ( newChild->parent() )
|
---|
1397 | newChild->parent()->removeChild( newChild );
|
---|
1398 |
|
---|
1399 | newChild->setParent( this );
|
---|
1400 |
|
---|
1401 | if ( oldChild->next )
|
---|
1402 | oldChild->next->prev = newChild;
|
---|
1403 | if ( oldChild->prev )
|
---|
1404 | oldChild->prev->next = newChild;
|
---|
1405 |
|
---|
1406 | newChild->next = oldChild->next;
|
---|
1407 | newChild->prev = oldChild->prev;
|
---|
1408 |
|
---|
1409 | if ( first == oldChild )
|
---|
1410 | first = newChild;
|
---|
1411 | if ( last == oldChild )
|
---|
1412 | last = newChild;
|
---|
1413 |
|
---|
1414 | oldChild->setNoParent();
|
---|
1415 | oldChild->next = 0;
|
---|
1416 | oldChild->prev = 0;
|
---|
1417 |
|
---|
1418 | // We are no longer interested in the old node
|
---|
1419 | if ( oldChild ) oldChild->deref();
|
---|
1420 |
|
---|
1421 | return oldChild;
|
---|
1422 | }
|
---|
1423 |
|
---|
1424 | QDomNodePrivate* QDomNodePrivate::removeChild( QDomNodePrivate* oldChild )
|
---|
1425 | {
|
---|
1426 | // Error check
|
---|
1427 | if ( oldChild->parent() != this )
|
---|
1428 | return 0;
|
---|
1429 |
|
---|
1430 | // "mark lists as dirty"
|
---|
1431 | qt_nodeListTime++;
|
---|
1432 |
|
---|
1433 | // Perhaps oldChild was just created with "createElement" or that. In this case
|
---|
1434 | // its parent is QDomDocument but it is not part of the documents child list.
|
---|
1435 | if ( oldChild->next == 0 && oldChild->prev == 0 && first != oldChild )
|
---|
1436 | return 0;
|
---|
1437 |
|
---|
1438 | if ( oldChild->next )
|
---|
1439 | oldChild->next->prev = oldChild->prev;
|
---|
1440 | if ( oldChild->prev )
|
---|
1441 | oldChild->prev->next = oldChild->next;
|
---|
1442 |
|
---|
1443 | if ( last == oldChild )
|
---|
1444 | last = oldChild->prev;
|
---|
1445 | if ( first == oldChild )
|
---|
1446 | first = oldChild->next;
|
---|
1447 |
|
---|
1448 | oldChild->setNoParent();
|
---|
1449 | oldChild->next = 0;
|
---|
1450 | oldChild->prev = 0;
|
---|
1451 |
|
---|
1452 | // We are no longer interested in the old node
|
---|
1453 | if ( oldChild ) oldChild->deref();
|
---|
1454 |
|
---|
1455 | return oldChild;
|
---|
1456 | }
|
---|
1457 |
|
---|
1458 | QDomNodePrivate* QDomNodePrivate::appendChild( QDomNodePrivate* newChild )
|
---|
1459 | {
|
---|
1460 | // No reference manipulation needed. Done in insertAfter.
|
---|
1461 | return insertAfter( newChild, 0 );
|
---|
1462 | }
|
---|
1463 |
|
---|
1464 | QDomDocumentPrivate* QDomNodePrivate::ownerDocument()
|
---|
1465 | {
|
---|
1466 | QDomNodePrivate* p = this;
|
---|
1467 | while ( p && !p->isDocument() ) {
|
---|
1468 | if ( !p->hasParent )
|
---|
1469 | return (QDomDocumentPrivate*)p->ownerNode;
|
---|
1470 | p = p->parent();
|
---|
1471 | }
|
---|
1472 |
|
---|
1473 | return (QDomDocumentPrivate*)p;
|
---|
1474 | }
|
---|
1475 |
|
---|
1476 | QDomNodePrivate* QDomNodePrivate::cloneNode( bool deep )
|
---|
1477 | {
|
---|
1478 | QDomNodePrivate* p = new QDomNodePrivate( this, deep );
|
---|
1479 | // We are not interested in this node
|
---|
1480 | p->deref();
|
---|
1481 | return p;
|
---|
1482 | }
|
---|
1483 |
|
---|
1484 | static void qNormalizeNode( QDomNodePrivate* n )
|
---|
1485 | {
|
---|
1486 | QDomNodePrivate* p = n->first;
|
---|
1487 | QDomTextPrivate* t = 0;
|
---|
1488 |
|
---|
1489 | while ( p ) {
|
---|
1490 | if ( p->isText() ) {
|
---|
1491 | if ( t ) {
|
---|
1492 | QDomNodePrivate* tmp = p->next;
|
---|
1493 | t->appendData( p->nodeValue() );
|
---|
1494 | n->removeChild( p );
|
---|
1495 | p = tmp;
|
---|
1496 | } else {
|
---|
1497 | t = (QDomTextPrivate*)p;
|
---|
1498 | p = p->next;
|
---|
1499 | }
|
---|
1500 | } else {
|
---|
1501 | p = p->next;
|
---|
1502 | t = 0;
|
---|
1503 | }
|
---|
1504 | }
|
---|
1505 | }
|
---|
1506 | void QDomNodePrivate::normalize()
|
---|
1507 | {
|
---|
1508 | // ### This one has moved from QDomElementPrivate to this position. It is
|
---|
1509 | // not tested.
|
---|
1510 | qNormalizeNode( this );
|
---|
1511 | }
|
---|
1512 |
|
---|
1513 | void QDomNodePrivate::save( QTextStream& s, int depth, int indent ) const
|
---|
1514 | {
|
---|
1515 | const QDomNodePrivate* n = first;
|
---|
1516 | while ( n ) {
|
---|
1517 | n->save( s, depth, indent );
|
---|
1518 | n = n->next;
|
---|
1519 | }
|
---|
1520 | }
|
---|
1521 |
|
---|
1522 | /**************************************************************
|
---|
1523 | *
|
---|
1524 | * QDomNode
|
---|
1525 | *
|
---|
1526 | **************************************************************/
|
---|
1527 |
|
---|
1528 | #define IMPL ((QDomNodePrivate*)impl)
|
---|
1529 |
|
---|
1530 | /*!
|
---|
1531 | \class QDomNode qdom.h
|
---|
1532 | \reentrant
|
---|
1533 | \brief The QDomNode class is the base class for all the nodes in a DOM tree.
|
---|
1534 | \if defined(commercial)
|
---|
1535 | It is part of the <a href="commercialeditions.html">Qt Enterprise Edition</a>.
|
---|
1536 | \endif
|
---|
1537 |
|
---|
1538 | \module XML
|
---|
1539 | \ingroup xml-tools
|
---|
1540 |
|
---|
1541 | Many functions in the DOM return a QDomNode.
|
---|
1542 |
|
---|
1543 | You can find out the type of a node using isAttr(),
|
---|
1544 | isCDATASection(), isDocumentFragment(), isDocument(),
|
---|
1545 | isDocumentType(), isElement(), isEntityReference(), isText(),
|
---|
1546 | isEntity(), isNotation(), isProcessingInstruction(),
|
---|
1547 | isCharacterData() and isComment().
|
---|
1548 |
|
---|
1549 | A QDomNode can be converted into one of its subclasses using
|
---|
1550 | toAttr(), toCDATASection(), toDocumentFragment(), toDocument(),
|
---|
1551 | toDocumentType(), toElement(), toEntityReference(), toText(),
|
---|
1552 | toEntity(), toNotation(), toProcessingInstruction(),
|
---|
1553 | toCharacterData() or toComment(). You can convert a node to a null
|
---|
1554 | node with clear().
|
---|
1555 |
|
---|
1556 | Copies of the QDomNode class share their data using explicit
|
---|
1557 | sharing. This means that modifying one node will change all
|
---|
1558 | copies. This is especially useful in combination with functions
|
---|
1559 | which return a QDomNode, e.g. firstChild(). You can make an
|
---|
1560 | independent (deep) copy of the node with cloneNode().
|
---|
1561 |
|
---|
1562 | Nodes are inserted with insertBefore(), insertAfter() or
|
---|
1563 | appendChild(). You can replace one node with another using
|
---|
1564 | replaceChild() and remove a node with removeChild().
|
---|
1565 |
|
---|
1566 | To traverse nodes use firstChild() to get a node's first child (if
|
---|
1567 | any), and nextSibling() to traverse. QDomNode also provides
|
---|
1568 | lastChild(), previousSibling() and parentNode(). To find the first
|
---|
1569 | child node with a particular node name use namedItem().
|
---|
1570 |
|
---|
1571 | To find out if a node has children use hasChildNodes() and to get
|
---|
1572 | a list of all of a node's children use childNodes().
|
---|
1573 |
|
---|
1574 | The node's name and value (the meaning of which varies depending
|
---|
1575 | on its type) is returned by nodeName() and nodeValue()
|
---|
1576 | respectively. The node's type is returned by nodeType(). The
|
---|
1577 | node's value can be set with setNodeValue().
|
---|
1578 |
|
---|
1579 | The document to which the node belongs is returned by
|
---|
1580 | ownerDocument().
|
---|
1581 |
|
---|
1582 | Adjacent QDomText nodes can be merged into a single node with
|
---|
1583 | normalize().
|
---|
1584 |
|
---|
1585 | \l QDomElement nodes have attributes which can be retrieved with
|
---|
1586 | attributes().
|
---|
1587 |
|
---|
1588 | QDomElement and QDomAttr nodes can have namespaces which can be
|
---|
1589 | retrieved with namespaceURI(). Their local name is retrieved with
|
---|
1590 | localName(), and their prefix with prefix(). The prefix can be set
|
---|
1591 | with setPrefix().
|
---|
1592 |
|
---|
1593 | You can write the XML representation of the node to a text stream
|
---|
1594 | with save().
|
---|
1595 |
|
---|
1596 | The following example looks for the first element in an XML document and
|
---|
1597 | prints the names of all the elements that are its direct children.
|
---|
1598 | \code
|
---|
1599 | QDomDocument d;
|
---|
1600 | d.setContent( someXML );
|
---|
1601 | QDomNode n = d.firstChild();
|
---|
1602 | while ( !n.isNull() ) {
|
---|
1603 | if ( n.isElement() ) {
|
---|
1604 | QDomElement e = n.toElement();
|
---|
1605 | cout << "Element name: " << e.tagName() << endl;
|
---|
1606 | break;
|
---|
1607 | }
|
---|
1608 | n = n.nextSibling();
|
---|
1609 | }
|
---|
1610 | \endcode
|
---|
1611 |
|
---|
1612 | For further information about the Document Object Model see \link
|
---|
1613 | http://www.w3.org/TR/REC-DOM-Level-1/\endlink and \link
|
---|
1614 | http://www.w3.org/TR/DOM-Level-2-Core/\endlink. For a more general
|
---|
1615 | introduction of the DOM implementation see the QDomDocument
|
---|
1616 | documentation.
|
---|
1617 | */
|
---|
1618 |
|
---|
1619 | /*!
|
---|
1620 | Constructs a \link isNull() null\endlink node.
|
---|
1621 | */
|
---|
1622 | QDomNode::QDomNode()
|
---|
1623 | {
|
---|
1624 | impl = 0;
|
---|
1625 | }
|
---|
1626 |
|
---|
1627 | /*!
|
---|
1628 | Constructs a copy of \a n.
|
---|
1629 |
|
---|
1630 | The data of the copy is shared (shallow copy): modifying one node
|
---|
1631 | will also change the other. If you want to make a deep copy, use
|
---|
1632 | cloneNode().
|
---|
1633 | */
|
---|
1634 | QDomNode::QDomNode( const QDomNode& n )
|
---|
1635 | {
|
---|
1636 | impl = n.impl;
|
---|
1637 | if ( impl ) impl->ref();
|
---|
1638 | }
|
---|
1639 |
|
---|
1640 | /*! \internal
|
---|
1641 | Constructs a new node for the data \a n.
|
---|
1642 | */
|
---|
1643 | QDomNode::QDomNode( QDomNodePrivate* n )
|
---|
1644 | {
|
---|
1645 | impl = n;
|
---|
1646 | if ( impl ) impl->ref();
|
---|
1647 | }
|
---|
1648 |
|
---|
1649 | /*!
|
---|
1650 | Assigns a copy of \a n to this DOM node.
|
---|
1651 |
|
---|
1652 | The data of the copy is shared (shallow copy): modifying one node
|
---|
1653 | will also change the other. If you want to make a deep copy, use
|
---|
1654 | cloneNode().
|
---|
1655 | */
|
---|
1656 | QDomNode& QDomNode::operator= ( const QDomNode& n )
|
---|
1657 | {
|
---|
1658 | if ( n.impl ) n.impl->ref();
|
---|
1659 | if ( impl && impl->deref() ) delete impl;
|
---|
1660 | impl = n.impl;
|
---|
1661 |
|
---|
1662 | return *this;
|
---|
1663 | }
|
---|
1664 |
|
---|
1665 | /*!
|
---|
1666 | Returns TRUE if \a n and this DOM node are equal; otherwise
|
---|
1667 | returns FALSE.
|
---|
1668 | */
|
---|
1669 | bool QDomNode::operator== ( const QDomNode& n ) const
|
---|
1670 | {
|
---|
1671 | return ( impl == n.impl );
|
---|
1672 | }
|
---|
1673 |
|
---|
1674 | /*!
|
---|
1675 | Returns TRUE if \a n and this DOM node are not equal; otherwise
|
---|
1676 | returns FALSE.
|
---|
1677 | */
|
---|
1678 | bool QDomNode::operator!= ( const QDomNode& n ) const
|
---|
1679 | {
|
---|
1680 | return ( impl != n.impl );
|
---|
1681 | }
|
---|
1682 |
|
---|
1683 | /*!
|
---|
1684 | Destroys the object and frees its resources.
|
---|
1685 | */
|
---|
1686 | QDomNode::~QDomNode()
|
---|
1687 | {
|
---|
1688 | if ( impl && impl->deref() ) delete impl;
|
---|
1689 | }
|
---|
1690 |
|
---|
1691 | /*!
|
---|
1692 | Returns the name of the node.
|
---|
1693 |
|
---|
1694 | The meaning of the name depends on the subclass:
|
---|
1695 | \table
|
---|
1696 | \header \i Name \i Meaning
|
---|
1697 | \row \i QDomAttr \i The name of the attribute
|
---|
1698 | \row \i QDomCDATASection \i The string "#cdata-section"
|
---|
1699 | \row \i QDomComment \i The string "#comment"
|
---|
1700 | \row \i QDomDocument \i The string "#document"
|
---|
1701 | \row \i QDomDocumentFragment \i The string "#document-fragment"
|
---|
1702 | \row \i QDomDocumentType \i The name of the document type
|
---|
1703 | \row \i QDomElement \i The tag name
|
---|
1704 | \row \i QDomEntity \i The name of the entity
|
---|
1705 | \row \i QDomEntityReference \i The name of the referenced entity
|
---|
1706 | \row \i QDomNotation \i The name of the notation
|
---|
1707 | \row \i QDomProcessingInstruction \i The target of the processing instruction
|
---|
1708 | \row \i QDomText \i The string "#text"
|
---|
1709 | \endtable
|
---|
1710 |
|
---|
1711 | \sa nodeValue()
|
---|
1712 | */
|
---|
1713 | QString QDomNode::nodeName() const
|
---|
1714 | {
|
---|
1715 | if ( !impl )
|
---|
1716 | return QString::null;
|
---|
1717 |
|
---|
1718 | if ( !IMPL->prefix.isEmpty() )
|
---|
1719 | return IMPL->prefix + ":" + IMPL->name;
|
---|
1720 | return IMPL->name;
|
---|
1721 | }
|
---|
1722 |
|
---|
1723 | /*!
|
---|
1724 | Returns the value of the node.
|
---|
1725 |
|
---|
1726 | The meaning of the value depends on the subclass:
|
---|
1727 | \table
|
---|
1728 | \header \i Name \i Meaning
|
---|
1729 | \row \i QDomAttr \i The attribute value
|
---|
1730 | \row \i QDomCDATASection \i The content of the CDATA section
|
---|
1731 | \row \i QDomComment \i The comment
|
---|
1732 | \row \i QDomProcessingInstruction \i The data of the processing intruction
|
---|
1733 | \row \i QDomText \i The text
|
---|
1734 | \endtable
|
---|
1735 |
|
---|
1736 | All the other subclasses do not have a node value and will return
|
---|
1737 | QString::null.
|
---|
1738 |
|
---|
1739 | \sa setNodeValue() nodeName()
|
---|
1740 | */
|
---|
1741 | QString QDomNode::nodeValue() const
|
---|
1742 | {
|
---|
1743 | if ( !impl )
|
---|
1744 | return QString::null;
|
---|
1745 | return IMPL->value;
|
---|
1746 | }
|
---|
1747 |
|
---|
1748 | /*!
|
---|
1749 | Sets the node's value to \a v.
|
---|
1750 |
|
---|
1751 | \sa nodeValue()
|
---|
1752 | */
|
---|
1753 | void QDomNode::setNodeValue( const QString& v )
|
---|
1754 | {
|
---|
1755 | if ( !impl )
|
---|
1756 | return;
|
---|
1757 | IMPL->setNodeValue( v );
|
---|
1758 | }
|
---|
1759 |
|
---|
1760 | /*!
|
---|
1761 | \enum QDomNode::NodeType
|
---|
1762 |
|
---|
1763 | This enum defines the type of the node:
|
---|
1764 | \value ElementNode
|
---|
1765 | \value AttributeNode
|
---|
1766 | \value TextNode
|
---|
1767 | \value CDATASectionNode
|
---|
1768 | \value EntityReferenceNode
|
---|
1769 | \value EntityNode
|
---|
1770 | \value ProcessingInstructionNode
|
---|
1771 | \value CommentNode
|
---|
1772 | \value DocumentNode
|
---|
1773 | \value DocumentTypeNode
|
---|
1774 | \value DocumentFragmentNode
|
---|
1775 | \value NotationNode
|
---|
1776 | \value BaseNode A QDomNode object, i.e. not a QDomNode subclass.
|
---|
1777 | \value CharacterDataNode
|
---|
1778 | */
|
---|
1779 |
|
---|
1780 | /*!
|
---|
1781 | Returns the type of the node.
|
---|
1782 |
|
---|
1783 | \sa toAttr(), toCDATASection(), toDocumentFragment(),
|
---|
1784 | toDocument() toDocumentType(), toElement(), toEntityReference(),
|
---|
1785 | toText(), toEntity() toNotation(), toProcessingInstruction(),
|
---|
1786 | toCharacterData(), toComment()
|
---|
1787 | */
|
---|
1788 | QDomNode::NodeType QDomNode::nodeType() const
|
---|
1789 | {
|
---|
1790 | if ( !impl )
|
---|
1791 | return QDomNode::BaseNode;
|
---|
1792 | return IMPL->nodeType();
|
---|
1793 | }
|
---|
1794 |
|
---|
1795 | /*!
|
---|
1796 | Returns the parent node. If this node has no parent, a null node
|
---|
1797 | is returned (i.e. a node for which isNull() returns TRUE).
|
---|
1798 | */
|
---|
1799 | QDomNode QDomNode::parentNode() const
|
---|
1800 | {
|
---|
1801 | if ( !impl )
|
---|
1802 | return QDomNode();
|
---|
1803 | return QDomNode( IMPL->parent() );
|
---|
1804 | }
|
---|
1805 |
|
---|
1806 | /*!
|
---|
1807 | Returns a list of all direct child nodes.
|
---|
1808 |
|
---|
1809 | Most often you will call this function on a QDomElement object.
|
---|
1810 |
|
---|
1811 | For example, if the XML document looks like this:
|
---|
1812 | \code
|
---|
1813 | <body>
|
---|
1814 | <h1>Heading</h1>
|
---|
1815 | <p>Hello <b>you</b></p>
|
---|
1816 | </body>
|
---|
1817 | \endcode
|
---|
1818 | Then the list of child nodes for the "body"-element will contain
|
---|
1819 | the node created by the <h1> tag and the node created by the
|
---|
1820 | <p> tag.
|
---|
1821 |
|
---|
1822 | The nodes in the list are not copied; so changing the nodes in the
|
---|
1823 | list will also change the children of this node.
|
---|
1824 |
|
---|
1825 | \sa firstChild() lastChild()
|
---|
1826 | */
|
---|
1827 | QDomNodeList QDomNode::childNodes() const
|
---|
1828 | {
|
---|
1829 | if ( !impl )
|
---|
1830 | return QDomNodeList();
|
---|
1831 | return QDomNodeList( new QDomNodeListPrivate( impl ) );
|
---|
1832 | }
|
---|
1833 |
|
---|
1834 | /*!
|
---|
1835 | Returns the first child of the node. If there is no child node, a
|
---|
1836 | \link isNull() null node\endlink is returned. Changing the
|
---|
1837 | returned node will also change the node in the document tree.
|
---|
1838 |
|
---|
1839 | \sa lastChild() childNodes()
|
---|
1840 | */
|
---|
1841 | QDomNode QDomNode::firstChild() const
|
---|
1842 | {
|
---|
1843 | if ( !impl )
|
---|
1844 | return QDomNode();
|
---|
1845 | return QDomNode( IMPL->first );
|
---|
1846 | }
|
---|
1847 |
|
---|
1848 | /*!
|
---|
1849 | Returns the last child of the node. If there is no child node, a
|
---|
1850 | \link isNull() null node\endlink is returned. Changing the
|
---|
1851 | returned node will also change the node in the document tree.
|
---|
1852 |
|
---|
1853 | \sa firstChild() childNodes()
|
---|
1854 | */
|
---|
1855 | QDomNode QDomNode::lastChild() const
|
---|
1856 | {
|
---|
1857 | if ( !impl )
|
---|
1858 | return QDomNode();
|
---|
1859 | return QDomNode( IMPL->last );
|
---|
1860 | }
|
---|
1861 |
|
---|
1862 | /*!
|
---|
1863 | Returns the previous sibling in the document tree. Changing the
|
---|
1864 | returned node will also change the node in the document tree.
|
---|
1865 |
|
---|
1866 | For example, if you have XML like this:
|
---|
1867 | \code
|
---|
1868 | <h1>Heading</h1>
|
---|
1869 | <p>The text...</p>
|
---|
1870 | <h2>Next heading</h2>
|
---|
1871 | \endcode
|
---|
1872 | and this QDomNode represents the <p> tag, previousSibling()
|
---|
1873 | will return the node representing the <h1> tag.
|
---|
1874 |
|
---|
1875 | \sa nextSibling()
|
---|
1876 | */
|
---|
1877 | QDomNode QDomNode::previousSibling() const
|
---|
1878 | {
|
---|
1879 | if ( !impl )
|
---|
1880 | return QDomNode();
|
---|
1881 | return QDomNode( IMPL->prev );
|
---|
1882 | }
|
---|
1883 |
|
---|
1884 | /*!
|
---|
1885 | Returns the next sibling in the document tree. Changing the
|
---|
1886 | returned node will also change the node in the document tree.
|
---|
1887 |
|
---|
1888 | If you have XML like this:
|
---|
1889 | \code
|
---|
1890 | <h1>Heading</h1>
|
---|
1891 | <p>The text...</p>
|
---|
1892 | <h2>Next heading</h2>
|
---|
1893 | \endcode
|
---|
1894 | and this QDomNode represents the <p> tag, nextSibling() will
|
---|
1895 | return the node representing the <h2> tag.
|
---|
1896 |
|
---|
1897 | \sa previousSibling()
|
---|
1898 | */
|
---|
1899 | QDomNode QDomNode::nextSibling() const
|
---|
1900 | {
|
---|
1901 | if ( !impl )
|
---|
1902 | return QDomNode();
|
---|
1903 | return QDomNode( IMPL->next );
|
---|
1904 | }
|
---|
1905 |
|
---|
1906 | /*!
|
---|
1907 | Returns a named node map of all attributes. Attributes are only
|
---|
1908 | provided for \l{QDomElement}s.
|
---|
1909 |
|
---|
1910 | Changing the attributes in the map will also change the attributes
|
---|
1911 | of this QDomNode.
|
---|
1912 | */
|
---|
1913 | QDomNamedNodeMap QDomNode::attributes() const
|
---|
1914 | {
|
---|
1915 | if ( !impl )
|
---|
1916 | return QDomNamedNodeMap();
|
---|
1917 |
|
---|
1918 | return QDomNamedNodeMap( impl->attributes() );
|
---|
1919 | }
|
---|
1920 |
|
---|
1921 | /*!
|
---|
1922 | Returns the document to which this node belongs.
|
---|
1923 | */
|
---|
1924 | QDomDocument QDomNode::ownerDocument() const
|
---|
1925 | {
|
---|
1926 | if ( !impl )
|
---|
1927 | return QDomDocument();
|
---|
1928 | return QDomDocument( IMPL->ownerDocument() );
|
---|
1929 | }
|
---|
1930 |
|
---|
1931 | /*!
|
---|
1932 | Creates a deep (not shallow) copy of the QDomNode.
|
---|
1933 |
|
---|
1934 | If \a deep is TRUE, then the cloning is done recursively which
|
---|
1935 | means that all the node's children are deep copied too. If \a deep
|
---|
1936 | is FALSE only the node itself is copied and the copy will have no
|
---|
1937 | child nodes.
|
---|
1938 | */
|
---|
1939 | QDomNode QDomNode::cloneNode( bool deep ) const
|
---|
1940 | {
|
---|
1941 | if ( !impl )
|
---|
1942 | return QDomNode();
|
---|
1943 | return QDomNode( IMPL->cloneNode( deep ) );
|
---|
1944 | }
|
---|
1945 |
|
---|
1946 | /*!
|
---|
1947 | Calling normalize() on an element converts all its children into a
|
---|
1948 | standard form. This means that adjacent QDomText objects will be
|
---|
1949 | merged into a single text object (QDomCDATASection nodes are not
|
---|
1950 | merged).
|
---|
1951 | */
|
---|
1952 | void QDomNode::normalize()
|
---|
1953 | {
|
---|
1954 | if ( !impl )
|
---|
1955 | return;
|
---|
1956 | IMPL->normalize();
|
---|
1957 | }
|
---|
1958 |
|
---|
1959 | /*!
|
---|
1960 | Returns TRUE if the DOM implementation implements the feature \a
|
---|
1961 | feature and this feature is supported by this node in the version
|
---|
1962 | \a version; otherwise returns FALSE.
|
---|
1963 |
|
---|
1964 | \sa QDomImplementation::hasFeature()
|
---|
1965 | */
|
---|
1966 | bool QDomNode::isSupported( const QString& feature, const QString& version ) const
|
---|
1967 | {
|
---|
1968 | QDomImplementation i;
|
---|
1969 | return i.hasFeature( feature, version );
|
---|
1970 | }
|
---|
1971 |
|
---|
1972 | /*!
|
---|
1973 | Returns the namespace URI of this node or QString::null if the
|
---|
1974 | node has no namespace URI.
|
---|
1975 |
|
---|
1976 | Only nodes of type \link QDomNode::NodeType ElementNode\endlink or
|
---|
1977 | \link QDomNode::NodeType AttributeNode\endlink can have
|
---|
1978 | namespaces. A namespace URI must be specified at creation time and
|
---|
1979 | cannot be changed later.
|
---|
1980 |
|
---|
1981 | \sa prefix() localName() QDomDocument::createElementNS()
|
---|
1982 | QDomDocument::createAttributeNS()
|
---|
1983 | */
|
---|
1984 | QString QDomNode::namespaceURI() const
|
---|
1985 | {
|
---|
1986 | if ( !impl )
|
---|
1987 | return QString::null;
|
---|
1988 | return IMPL->namespaceURI;
|
---|
1989 | }
|
---|
1990 |
|
---|
1991 | /*!
|
---|
1992 | Returns the namespace prefix of the node or QString::null if the
|
---|
1993 | node has no namespace prefix.
|
---|
1994 |
|
---|
1995 | Only nodes of type \link QDomNode::NodeType ElementNode\endlink or
|
---|
1996 | \link QDomNode::NodeType AttributeNode\endlink can have
|
---|
1997 | namespaces. A namespace prefix must be specified at creation time.
|
---|
1998 | If a node was created with a namespace prefix, you can change it
|
---|
1999 | later with setPrefix().
|
---|
2000 |
|
---|
2001 | If you create an element or attribute with
|
---|
2002 | QDomDocument::createElement() or QDomDocument::createAttribute(),
|
---|
2003 | the prefix will be QString::null. If you use
|
---|
2004 | QDomDocument::createElementNS() or
|
---|
2005 | QDomDocument::createAttributeNS() instead, the prefix will not be
|
---|
2006 | QString::null; but it might be an empty string if the name does
|
---|
2007 | not have a prefix.
|
---|
2008 |
|
---|
2009 | \sa setPrefix() localName() namespaceURI()
|
---|
2010 | QDomDocument::createElementNS() QDomDocument::createAttributeNS()
|
---|
2011 | */
|
---|
2012 | QString QDomNode::prefix() const
|
---|
2013 | {
|
---|
2014 | if ( !impl )
|
---|
2015 | return QString::null;
|
---|
2016 | return IMPL->prefix;
|
---|
2017 | }
|
---|
2018 |
|
---|
2019 | /*!
|
---|
2020 | If the node has a namespace prefix, this function changes the
|
---|
2021 | namespace prefix of the node to \a pre. Otherwise this function
|
---|
2022 | does nothing.
|
---|
2023 |
|
---|
2024 | Only nodes of type \link QDomNode::NodeType ElementNode\endlink or
|
---|
2025 | \link QDomNode::NodeType AttributeNode\endlink can have
|
---|
2026 | namespaces. A namespace prefix must have be specified at creation
|
---|
2027 | time; it is not possible to add a namespace prefix afterwards.
|
---|
2028 |
|
---|
2029 | \sa prefix() localName() namespaceURI()
|
---|
2030 | QDomDocument::createElementNS() QDomDocument::createAttributeNS()
|
---|
2031 | */
|
---|
2032 | void QDomNode::setPrefix( const QString& pre )
|
---|
2033 | {
|
---|
2034 | if ( !impl || IMPL->prefix.isNull() )
|
---|
2035 | return;
|
---|
2036 | if ( isAttr() || isElement() )
|
---|
2037 | IMPL->prefix = pre;
|
---|
2038 | }
|
---|
2039 |
|
---|
2040 | /*!
|
---|
2041 | If the node uses namespaces, this function returns the local name
|
---|
2042 | of the node; otherwise it returns QString::null.
|
---|
2043 |
|
---|
2044 | Only nodes of type \link QDomNode::NodeType ElementNode\endlink or
|
---|
2045 | \link QDomNode::NodeType AttributeNode\endlink can have
|
---|
2046 | namespaces. A namespace must have been specified at creation time;
|
---|
2047 | it is not possible to add a namespace afterwards.
|
---|
2048 |
|
---|
2049 | \sa prefix() namespaceURI() QDomDocument::createElementNS()
|
---|
2050 | QDomDocument::createAttributeNS()
|
---|
2051 | */
|
---|
2052 | QString QDomNode::localName() const
|
---|
2053 | {
|
---|
2054 | if ( !impl || IMPL->createdWithDom1Interface )
|
---|
2055 | return QString::null;
|
---|
2056 | return IMPL->name;
|
---|
2057 | }
|
---|
2058 |
|
---|
2059 | /*!
|
---|
2060 | Returns TRUE if the node has attributes; otherwise returns FALSE.
|
---|
2061 |
|
---|
2062 | \sa attributes()
|
---|
2063 | */
|
---|
2064 | bool QDomNode::hasAttributes() const
|
---|
2065 | {
|
---|
2066 | if ( !impl )
|
---|
2067 | return FALSE;
|
---|
2068 | return IMPL->hasAttributes();
|
---|
2069 | }
|
---|
2070 |
|
---|
2071 | /*!
|
---|
2072 | Inserts the node \a newChild before the child node \a refChild.
|
---|
2073 | \a refChild must be a direct child of this node. If \a refChild is
|
---|
2074 | \link isNull() null\endlink then \a newChild is inserted as the
|
---|
2075 | node's first child.
|
---|
2076 |
|
---|
2077 | If \a newChild is the child of another node, it is reparented to
|
---|
2078 | this node. If \a newChild is a child of this node, then its
|
---|
2079 | position in the list of children is changed.
|
---|
2080 |
|
---|
2081 | If \a newChild is a QDomDocumentFragment, then the children of the
|
---|
2082 | fragment are removed from the fragment and inserted before \a
|
---|
2083 | refChild.
|
---|
2084 |
|
---|
2085 | Returns a new reference to \a newChild on success or a \link
|
---|
2086 | isNull() null node\endlink on failure.
|
---|
2087 |
|
---|
2088 | \sa insertAfter() replaceChild() removeChild() appendChild()
|
---|
2089 | */
|
---|
2090 | QDomNode QDomNode::insertBefore( const QDomNode& newChild, const QDomNode& refChild )
|
---|
2091 | {
|
---|
2092 | if ( !impl )
|
---|
2093 | return QDomNode();
|
---|
2094 | return QDomNode( IMPL->insertBefore( newChild.impl, refChild.impl ) );
|
---|
2095 | }
|
---|
2096 |
|
---|
2097 | /*!
|
---|
2098 | Inserts the node \a newChild after the child node \a refChild. \a
|
---|
2099 | refChild must be a direct child of this node. If \a refChild is
|
---|
2100 | \link isNull() null\endlink then \a newChild is appended as this
|
---|
2101 | node's last child.
|
---|
2102 |
|
---|
2103 | If \a newChild is the child of another node, it is reparented to
|
---|
2104 | this node. If \a newChild is a child of this node, then its
|
---|
2105 | position in the list of children is changed.
|
---|
2106 |
|
---|
2107 | If \a newChild is a QDomDocumentFragment, then the children of the
|
---|
2108 | fragment are removed from the fragment and inserted after \a
|
---|
2109 | refChild.
|
---|
2110 |
|
---|
2111 | Returns a new reference to \a newChild on success or a \link
|
---|
2112 | isNull() null node\endlink on failure.
|
---|
2113 |
|
---|
2114 | \sa insertBefore() replaceChild() removeChild() appendChild()
|
---|
2115 | */
|
---|
2116 | QDomNode QDomNode::insertAfter( const QDomNode& newChild, const QDomNode& refChild )
|
---|
2117 | {
|
---|
2118 | if ( !impl )
|
---|
2119 | return QDomNode();
|
---|
2120 | return QDomNode( IMPL->insertAfter( newChild.impl, refChild.impl ) );
|
---|
2121 | }
|
---|
2122 |
|
---|
2123 | /*!
|
---|
2124 | Replaces \a oldChild with \a newChild. \a oldChild must be a
|
---|
2125 | direct child of this node.
|
---|
2126 |
|
---|
2127 | If \a newChild is the child of another node, it is reparented to
|
---|
2128 | this node. If \a newChild is a child of this node, then its
|
---|
2129 | position in the list of children is changed.
|
---|
2130 |
|
---|
2131 | If \a newChild is a QDomDocumentFragment, then \a oldChild is
|
---|
2132 | replaced by all of the children of the fragment.
|
---|
2133 |
|
---|
2134 | Returns a new reference to \a oldChild on success or a \link
|
---|
2135 | isNull() null node\endlink an failure.
|
---|
2136 |
|
---|
2137 | \sa insertBefore() insertAfter() removeChild() appendChild()
|
---|
2138 | */
|
---|
2139 | QDomNode QDomNode::replaceChild( const QDomNode& newChild, const QDomNode& oldChild )
|
---|
2140 | {
|
---|
2141 | if ( !impl )
|
---|
2142 | return QDomNode();
|
---|
2143 | return QDomNode( IMPL->replaceChild( newChild.impl, oldChild.impl ) );
|
---|
2144 | }
|
---|
2145 |
|
---|
2146 | /*!
|
---|
2147 | Removes \a oldChild from the list of children. \a oldChild must be
|
---|
2148 | a direct child of this node.
|
---|
2149 |
|
---|
2150 | Returns a new reference to \a oldChild on success or a \link
|
---|
2151 | isNull() null node\endlink on failure.
|
---|
2152 |
|
---|
2153 | \sa insertBefore() insertAfter() replaceChild() appendChild()
|
---|
2154 | */
|
---|
2155 | QDomNode QDomNode::removeChild( const QDomNode& oldChild )
|
---|
2156 | {
|
---|
2157 | if ( !impl )
|
---|
2158 | return QDomNode();
|
---|
2159 |
|
---|
2160 | if ( oldChild.isNull() )
|
---|
2161 | return QDomNode();
|
---|
2162 |
|
---|
2163 | return QDomNode( IMPL->removeChild( oldChild.impl ) );
|
---|
2164 | }
|
---|
2165 |
|
---|
2166 | /*!
|
---|
2167 | Appends \a newChild as the node's last child.
|
---|
2168 |
|
---|
2169 | If \a newChild is the child of another node, it is reparented to
|
---|
2170 | this node. If \a newChild is a child of this node, then its
|
---|
2171 | position in the list of children is changed.
|
---|
2172 |
|
---|
2173 | If \a newChild is a QDomDocumentFragment, then the children of the
|
---|
2174 | fragment are removed from the fragment and appended.
|
---|
2175 |
|
---|
2176 | Returns a new reference to \a newChild.
|
---|
2177 |
|
---|
2178 | \sa insertBefore() insertAfter() replaceChild() removeChild()
|
---|
2179 | */
|
---|
2180 | QDomNode QDomNode::appendChild( const QDomNode& newChild )
|
---|
2181 | {
|
---|
2182 | if ( !impl )
|
---|
2183 | return QDomNode();
|
---|
2184 | return QDomNode( IMPL->appendChild( newChild.impl ) );
|
---|
2185 | }
|
---|
2186 |
|
---|
2187 | /*!
|
---|
2188 | Returns TRUE if the node has one or more children; otherwise
|
---|
2189 | returns FALSE.
|
---|
2190 | */
|
---|
2191 | bool QDomNode::hasChildNodes() const
|
---|
2192 | {
|
---|
2193 | if ( !impl )
|
---|
2194 | return FALSE;
|
---|
2195 | return IMPL->first != 0;
|
---|
2196 | }
|
---|
2197 |
|
---|
2198 | /*!
|
---|
2199 | Returns TRUE if this node is null (i.e. if it has no type or
|
---|
2200 | contents); otherwise returns FALSE.
|
---|
2201 | */
|
---|
2202 | bool QDomNode::isNull() const
|
---|
2203 | {
|
---|
2204 | return ( impl == 0 );
|
---|
2205 | }
|
---|
2206 |
|
---|
2207 | /*!
|
---|
2208 | Converts the node into a null node; if it was not a null node
|
---|
2209 | before, its type and contents are deleted.
|
---|
2210 |
|
---|
2211 | \sa isNull()
|
---|
2212 | */
|
---|
2213 | void QDomNode::clear()
|
---|
2214 | {
|
---|
2215 | if ( impl && impl->deref() ) delete impl;
|
---|
2216 | impl = 0;
|
---|
2217 | }
|
---|
2218 |
|
---|
2219 | /*!
|
---|
2220 | Returns the first direct child node for which nodeName() equals \a
|
---|
2221 | name.
|
---|
2222 |
|
---|
2223 | If no such direct child exists, a \link isNull() null node\endlink
|
---|
2224 | is returned.
|
---|
2225 |
|
---|
2226 | \sa nodeName()
|
---|
2227 | */
|
---|
2228 | QDomNode QDomNode::namedItem( const QString& name ) const
|
---|
2229 | {
|
---|
2230 | if ( !impl )
|
---|
2231 | return QDomNode();
|
---|
2232 | return QDomNode( impl->namedItem( name ) );
|
---|
2233 | }
|
---|
2234 |
|
---|
2235 | /*!
|
---|
2236 | Writes the XML representation of the node and all its children to
|
---|
2237 | the stream \a str. This function uses \a indent as the amount of
|
---|
2238 | space to indent the node.
|
---|
2239 | */
|
---|
2240 | void QDomNode::save( QTextStream& str, int indent ) const
|
---|
2241 | {
|
---|
2242 | if ( impl )
|
---|
2243 | IMPL->save( str, 1, indent );
|
---|
2244 | }
|
---|
2245 |
|
---|
2246 | /*!
|
---|
2247 | \relates QDomNode
|
---|
2248 |
|
---|
2249 | Writes the XML representation of the node \a node and all its
|
---|
2250 | children to the stream \a str.
|
---|
2251 | */
|
---|
2252 | QTextStream& operator<<( QTextStream& str, const QDomNode& node )
|
---|
2253 | {
|
---|
2254 | node.save( str, 1 );
|
---|
2255 |
|
---|
2256 | return str;
|
---|
2257 | }
|
---|
2258 |
|
---|
2259 | /*!
|
---|
2260 | Returns TRUE if the node is an attribute; otherwise returns FALSE.
|
---|
2261 |
|
---|
2262 | If this function returns TRUE, it does not imply that this object
|
---|
2263 | is a QDomAttribute; you can get the QDomAttribute with
|
---|
2264 | toAttribute().
|
---|
2265 |
|
---|
2266 | \sa toAttr()
|
---|
2267 | */
|
---|
2268 | bool QDomNode::isAttr() const
|
---|
2269 | {
|
---|
2270 | if(impl)
|
---|
2271 | return impl->isAttr();
|
---|
2272 | return FALSE;
|
---|
2273 | }
|
---|
2274 |
|
---|
2275 | /*!
|
---|
2276 | Returns TRUE if the node is a CDATA section; otherwise returns
|
---|
2277 | FALSE.
|
---|
2278 |
|
---|
2279 | If this function returns TRUE, it does not imply that this object
|
---|
2280 | is a QDomCDATASection; you can get the QDomCDATASection with
|
---|
2281 | toCDATASection().
|
---|
2282 |
|
---|
2283 | \sa toCDATASection()
|
---|
2284 | */
|
---|
2285 | bool QDomNode::isCDATASection() const
|
---|
2286 | {
|
---|
2287 | if(impl)
|
---|
2288 | return impl->isCDATASection();
|
---|
2289 | return FALSE;
|
---|
2290 | }
|
---|
2291 |
|
---|
2292 | /*!
|
---|
2293 | Returns TRUE if the node is a document fragment; otherwise returns
|
---|
2294 | FALSE.
|
---|
2295 |
|
---|
2296 | If this function returns TRUE, it does not imply that this object
|
---|
2297 | is a QDomDocumentFragment; you can get the QDomDocumentFragment
|
---|
2298 | with toDocumentFragment().
|
---|
2299 |
|
---|
2300 | \sa toDocumentFragment()
|
---|
2301 | */
|
---|
2302 | bool QDomNode::isDocumentFragment() const
|
---|
2303 | {
|
---|
2304 | if(impl)
|
---|
2305 | return impl->isDocumentFragment();
|
---|
2306 | return FALSE;
|
---|
2307 | }
|
---|
2308 |
|
---|
2309 | /*!
|
---|
2310 | Returns TRUE if the node is a document; otherwise returns FALSE.
|
---|
2311 |
|
---|
2312 | If this function returns TRUE, it does not imply that this object
|
---|
2313 | is a QDomDocument; you can get the QDomDocument with toDocument().
|
---|
2314 |
|
---|
2315 | \sa toDocument()
|
---|
2316 | */
|
---|
2317 | bool QDomNode::isDocument() const
|
---|
2318 | {
|
---|
2319 | if(impl)
|
---|
2320 | return impl->isDocument();
|
---|
2321 | return FALSE;
|
---|
2322 | }
|
---|
2323 |
|
---|
2324 | /*!
|
---|
2325 | Returns TRUE if the node is a document type; otherwise returns
|
---|
2326 | FALSE.
|
---|
2327 |
|
---|
2328 | If this function returns TRUE, it does not imply that this object
|
---|
2329 | is a QDomDocumentType; you can get the QDomDocumentType with
|
---|
2330 | toDocumentType().
|
---|
2331 |
|
---|
2332 | \sa toDocumentType()
|
---|
2333 | */
|
---|
2334 | bool QDomNode::isDocumentType() const
|
---|
2335 | {
|
---|
2336 | if(impl)
|
---|
2337 | return impl->isDocumentType();
|
---|
2338 | return FALSE;
|
---|
2339 | }
|
---|
2340 |
|
---|
2341 | /*!
|
---|
2342 | Returns TRUE if the node is an element; otherwise returns FALSE.
|
---|
2343 |
|
---|
2344 | If this function returns TRUE, it does not imply that this object
|
---|
2345 | is a QDomElement; you can get the QDomElement with toElement().
|
---|
2346 |
|
---|
2347 | \sa toElement()
|
---|
2348 | */
|
---|
2349 | bool QDomNode::isElement() const
|
---|
2350 | {
|
---|
2351 | if(impl)
|
---|
2352 | return impl->isElement();
|
---|
2353 | return FALSE;
|
---|
2354 | }
|
---|
2355 |
|
---|
2356 | /*!
|
---|
2357 | Returns TRUE if the node is an entity reference; otherwise returns
|
---|
2358 | FALSE.
|
---|
2359 |
|
---|
2360 | If this function returns TRUE, it does not imply that this object
|
---|
2361 | is a QDomEntityReference; you can get the QDomEntityReference with
|
---|
2362 | toEntityReference().
|
---|
2363 |
|
---|
2364 | \sa toEntityReference()
|
---|
2365 | */
|
---|
2366 | bool QDomNode::isEntityReference() const
|
---|
2367 | {
|
---|
2368 | if(impl)
|
---|
2369 | return impl->isEntityReference();
|
---|
2370 | return FALSE;
|
---|
2371 | }
|
---|
2372 |
|
---|
2373 | /*!
|
---|
2374 | Returns TRUE if the node is a text node; otherwise returns FALSE.
|
---|
2375 |
|
---|
2376 | If this function returns TRUE, it does not imply that this object
|
---|
2377 | is a QDomText; you can get the QDomText with toText().
|
---|
2378 |
|
---|
2379 | \sa toText()
|
---|
2380 | */
|
---|
2381 | bool QDomNode::isText() const
|
---|
2382 | {
|
---|
2383 | if(impl)
|
---|
2384 | return impl->isText();
|
---|
2385 | return FALSE;
|
---|
2386 | }
|
---|
2387 |
|
---|
2388 | /*!
|
---|
2389 | Returns TRUE if the node is an entity; otherwise returns FALSE.
|
---|
2390 |
|
---|
2391 | If this function returns TRUE, it does not imply that this object
|
---|
2392 | is a QDomEntity; you can get the QDomEntity with toEntity().
|
---|
2393 |
|
---|
2394 | \sa toEntity()
|
---|
2395 | */
|
---|
2396 | bool QDomNode::isEntity() const
|
---|
2397 | {
|
---|
2398 | if(impl)
|
---|
2399 | return impl->isEntity();
|
---|
2400 | return FALSE;
|
---|
2401 | }
|
---|
2402 |
|
---|
2403 | /*!
|
---|
2404 | Returns TRUE if the node is a notation; otherwise returns FALSE.
|
---|
2405 |
|
---|
2406 | If this function returns TRUE, it does not imply that this object
|
---|
2407 | is a QDomNotation; you can get the QDomNotation with toNotation().
|
---|
2408 |
|
---|
2409 | \sa toNotation()
|
---|
2410 | */
|
---|
2411 | bool QDomNode::isNotation() const
|
---|
2412 | {
|
---|
2413 | if(impl)
|
---|
2414 | return impl->isNotation();
|
---|
2415 | return FALSE;
|
---|
2416 | }
|
---|
2417 |
|
---|
2418 | /*!
|
---|
2419 | Returns TRUE if the node is a processing instruction; otherwise
|
---|
2420 | returns FALSE.
|
---|
2421 |
|
---|
2422 | If this function returns TRUE, it does not imply that this object
|
---|
2423 | is a QDomProcessingInstruction; you can get the
|
---|
2424 | QProcessingInstruction with toProcessingInstruction().
|
---|
2425 |
|
---|
2426 | \sa toProcessingInstruction()
|
---|
2427 | */
|
---|
2428 | bool QDomNode::isProcessingInstruction() const
|
---|
2429 | {
|
---|
2430 | if(impl)
|
---|
2431 | return impl->isProcessingInstruction();
|
---|
2432 | return FALSE;
|
---|
2433 | }
|
---|
2434 |
|
---|
2435 | /*!
|
---|
2436 | Returns TRUE if the node is a character data node; otherwise
|
---|
2437 | returns FALSE.
|
---|
2438 |
|
---|
2439 | If this function returns TRUE, it does not imply that this object
|
---|
2440 | is a QDomCharacterData; you can get the QDomCharacterData with
|
---|
2441 | toCharacterData().
|
---|
2442 |
|
---|
2443 | \sa toCharacterData()
|
---|
2444 | */
|
---|
2445 | bool QDomNode::isCharacterData() const
|
---|
2446 | {
|
---|
2447 | if(impl)
|
---|
2448 | return impl->isCharacterData();
|
---|
2449 | return FALSE;
|
---|
2450 | }
|
---|
2451 |
|
---|
2452 | /*!
|
---|
2453 | Returns TRUE if the node is a comment; otherwise returns FALSE.
|
---|
2454 |
|
---|
2455 | If this function returns TRUE, it does not imply that this object
|
---|
2456 | is a QDomComment; you can get the QDomComment with toComment().
|
---|
2457 |
|
---|
2458 | \sa toComment()
|
---|
2459 | */
|
---|
2460 | bool QDomNode::isComment() const
|
---|
2461 | {
|
---|
2462 | if(impl)
|
---|
2463 | return impl->isComment();
|
---|
2464 | return FALSE;
|
---|
2465 | }
|
---|
2466 |
|
---|
2467 | #undef IMPL
|
---|
2468 |
|
---|
2469 | /**************************************************************
|
---|
2470 | *
|
---|
2471 | * QDomNamedNodeMapPrivate
|
---|
2472 | *
|
---|
2473 | **************************************************************/
|
---|
2474 |
|
---|
2475 | QDomNamedNodeMapPrivate::QDomNamedNodeMapPrivate( QDomNodePrivate* n )
|
---|
2476 | {
|
---|
2477 | readonly = FALSE;
|
---|
2478 | parent = n;
|
---|
2479 | appendToParent = FALSE;
|
---|
2480 | }
|
---|
2481 |
|
---|
2482 | QDomNamedNodeMapPrivate::~QDomNamedNodeMapPrivate()
|
---|
2483 | {
|
---|
2484 | clearMap();
|
---|
2485 | }
|
---|
2486 |
|
---|
2487 | QDomNamedNodeMapPrivate* QDomNamedNodeMapPrivate::clone( QDomNodePrivate* p )
|
---|
2488 | {
|
---|
2489 | QDomNamedNodeMapPrivate* m = new QDomNamedNodeMapPrivate( p );
|
---|
2490 | m->readonly = readonly;
|
---|
2491 | m->appendToParent = appendToParent;
|
---|
2492 |
|
---|
2493 | QDictIterator<QDomNodePrivate> it ( map );
|
---|
2494 | for ( ; it.current(); ++it )
|
---|
2495 | m->setNamedItem( it.current()->cloneNode() );
|
---|
2496 |
|
---|
2497 | // we are no longer interested in ownership
|
---|
2498 | m->deref();
|
---|
2499 | return m;
|
---|
2500 | }
|
---|
2501 |
|
---|
2502 | void QDomNamedNodeMapPrivate::clearMap()
|
---|
2503 | {
|
---|
2504 | // Dereference all of our children if we took references
|
---|
2505 | if ( !appendToParent ) {
|
---|
2506 | QDictIterator<QDomNodePrivate> it( map );
|
---|
2507 | for ( ; it.current(); ++it )
|
---|
2508 | if ( it.current()->deref() )
|
---|
2509 | delete it.current();
|
---|
2510 | }
|
---|
2511 |
|
---|
2512 | map.clear();
|
---|
2513 | }
|
---|
2514 |
|
---|
2515 | QDomNodePrivate* QDomNamedNodeMapPrivate::namedItem( const QString& name ) const
|
---|
2516 | {
|
---|
2517 | QDomNodePrivate* p = map[ name ];
|
---|
2518 | return p;
|
---|
2519 | }
|
---|
2520 |
|
---|
2521 | QDomNodePrivate* QDomNamedNodeMapPrivate::namedItemNS( const QString& nsURI, const QString& localName ) const
|
---|
2522 | {
|
---|
2523 | QDictIterator<QDomNodePrivate> it( map );
|
---|
2524 | QDomNodePrivate *n = it.current();
|
---|
2525 | while ( n ) {
|
---|
2526 | if ( !n->prefix.isNull() ) {
|
---|
2527 | // node has a namespace
|
---|
2528 | if ( n->namespaceURI==nsURI && n->name==localName ) {
|
---|
2529 | return n;
|
---|
2530 | }
|
---|
2531 | }
|
---|
2532 | ++it;
|
---|
2533 | n = it.current();
|
---|
2534 | }
|
---|
2535 | return 0;
|
---|
2536 | }
|
---|
2537 |
|
---|
2538 | QDomNodePrivate* QDomNamedNodeMapPrivate::setNamedItem( QDomNodePrivate* arg )
|
---|
2539 | {
|
---|
2540 | if ( readonly || !arg )
|
---|
2541 | return 0;
|
---|
2542 |
|
---|
2543 | if ( appendToParent )
|
---|
2544 | return parent->appendChild( arg );
|
---|
2545 |
|
---|
2546 | QDomNodePrivate *n = map[ arg->nodeName() ];
|
---|
2547 | // We take a reference
|
---|
2548 | arg->ref();
|
---|
2549 | map.insert( arg->nodeName(), arg );
|
---|
2550 | return n;
|
---|
2551 | }
|
---|
2552 |
|
---|
2553 | QDomNodePrivate* QDomNamedNodeMapPrivate::setNamedItemNS( QDomNodePrivate* arg )
|
---|
2554 | {
|
---|
2555 | if ( readonly || !arg )
|
---|
2556 | return 0;
|
---|
2557 |
|
---|
2558 | if ( appendToParent )
|
---|
2559 | return parent->appendChild( arg );
|
---|
2560 |
|
---|
2561 | if ( !arg->prefix.isNull() ) {
|
---|
2562 | // node has a namespace
|
---|
2563 | QDomNodePrivate *n = namedItemNS( arg->namespaceURI, arg->name );
|
---|
2564 | // We take a reference
|
---|
2565 | arg->ref();
|
---|
2566 | map.insert( arg->nodeName(), arg );
|
---|
2567 | return n;
|
---|
2568 | } else {
|
---|
2569 | // ### check the following code if it is ok
|
---|
2570 | return setNamedItem( arg );
|
---|
2571 | }
|
---|
2572 | }
|
---|
2573 |
|
---|
2574 | QDomNodePrivate* QDomNamedNodeMapPrivate::removeNamedItem( const QString& name )
|
---|
2575 | {
|
---|
2576 | if ( readonly )
|
---|
2577 | return 0;
|
---|
2578 |
|
---|
2579 | QDomNodePrivate* p = namedItem( name );
|
---|
2580 | if ( p == 0 )
|
---|
2581 | return 0;
|
---|
2582 | if ( appendToParent )
|
---|
2583 | return parent->removeChild( p );
|
---|
2584 |
|
---|
2585 | map.remove( p->nodeName() );
|
---|
2586 | // We took a reference, so we have to free one here
|
---|
2587 | p->deref();
|
---|
2588 | return p;
|
---|
2589 | }
|
---|
2590 |
|
---|
2591 | QDomNodePrivate* QDomNamedNodeMapPrivate::item( int index ) const
|
---|
2592 | {
|
---|
2593 | if ( (uint)index >= length() )
|
---|
2594 | return 0;
|
---|
2595 |
|
---|
2596 | QDictIterator<QDomNodePrivate> it( map );
|
---|
2597 | for ( int i = 0; i < index; ++i, ++it )
|
---|
2598 | ;
|
---|
2599 | return it.current();
|
---|
2600 | }
|
---|
2601 |
|
---|
2602 | uint QDomNamedNodeMapPrivate::length() const
|
---|
2603 | {
|
---|
2604 | return map.count();
|
---|
2605 | }
|
---|
2606 |
|
---|
2607 | bool QDomNamedNodeMapPrivate::contains( const QString& name ) const
|
---|
2608 | {
|
---|
2609 | return ( map[ name ] != 0 );
|
---|
2610 | }
|
---|
2611 |
|
---|
2612 | bool QDomNamedNodeMapPrivate::containsNS( const QString& nsURI, const QString & localName ) const
|
---|
2613 | {
|
---|
2614 | return ( namedItemNS( nsURI, localName ) != 0 );
|
---|
2615 | }
|
---|
2616 |
|
---|
2617 | /**************************************************************
|
---|
2618 | *
|
---|
2619 | * QDomNamedNodeMap
|
---|
2620 | *
|
---|
2621 | **************************************************************/
|
---|
2622 |
|
---|
2623 | #define IMPL ((QDomNamedNodeMapPrivate*)impl)
|
---|
2624 |
|
---|
2625 | /*!
|
---|
2626 | \class QDomNamedNodeMap qdom.h
|
---|
2627 | \reentrant
|
---|
2628 | \brief The QDomNamedNodeMap class contains a collection of nodes
|
---|
2629 | that can be accessed by name.
|
---|
2630 | \if defined(commercial)
|
---|
2631 | It is part of the <a href="commercialeditions.html">Qt Enterprise Edition</a>.
|
---|
2632 | \endif
|
---|
2633 |
|
---|
2634 | \module XML
|
---|
2635 | \ingroup xml-tools
|
---|
2636 |
|
---|
2637 | Note that QDomNamedNodeMap does not inherit from QDomNodeList.
|
---|
2638 | QDomNamedNodeMaps do not provide any specific node ordering.
|
---|
2639 | Although nodes in a QDomNamedNodeMap may be accessed by an ordinal
|
---|
2640 | index, this is simply to allow a convenient enumeration of the
|
---|
2641 | contents of a QDomNamedNodeMap, and does not imply that the DOM
|
---|
2642 | specifies an ordering of the nodes.
|
---|
2643 |
|
---|
2644 | The QDomNamedNodeMap is used in three places:
|
---|
2645 | \list 1
|
---|
2646 | \i QDomDocumentType::entities() returns a map of all entities
|
---|
2647 | described in the DTD.
|
---|
2648 | \i QDomDocumentType::notations() returns a map of all notations
|
---|
2649 | described in the DTD.
|
---|
2650 | \i QDomNode::attributes() returns a map of all attributes of an
|
---|
2651 | element.
|
---|
2652 | \endlist
|
---|
2653 |
|
---|
2654 | Items in the map are identified by the name which QDomNode::name()
|
---|
2655 | returns. Nodes are retrieved using namedItem(), namedItemNS() or
|
---|
2656 | item(). New nodes are inserted with setNamedItem() or
|
---|
2657 | setNamedItemNS() and removed with removeNamedItem() or
|
---|
2658 | removeNamedItemNS(). Use contains() to see if an item with the
|
---|
2659 | given name is in the named node map. The number of items is
|
---|
2660 | returned by length().
|
---|
2661 |
|
---|
2662 | Terminology: in this class we use "item" and "node"
|
---|
2663 | interchangeably.
|
---|
2664 | */
|
---|
2665 |
|
---|
2666 | /*!
|
---|
2667 | Constructs an empty named node map.
|
---|
2668 | */
|
---|
2669 | QDomNamedNodeMap::QDomNamedNodeMap()
|
---|
2670 | {
|
---|
2671 | impl = 0;
|
---|
2672 | }
|
---|
2673 |
|
---|
2674 | /*!
|
---|
2675 | Constructs a copy of \a n.
|
---|
2676 | */
|
---|
2677 | QDomNamedNodeMap::QDomNamedNodeMap( const QDomNamedNodeMap& n )
|
---|
2678 | {
|
---|
2679 | impl = n.impl;
|
---|
2680 | if ( impl )
|
---|
2681 | impl->ref();
|
---|
2682 | }
|
---|
2683 |
|
---|
2684 | QDomNamedNodeMap::QDomNamedNodeMap( QDomNamedNodeMapPrivate* n )
|
---|
2685 | {
|
---|
2686 | impl = n;
|
---|
2687 | if ( impl )
|
---|
2688 | impl->ref();
|
---|
2689 | }
|
---|
2690 |
|
---|
2691 | /*!
|
---|
2692 | Assigns \a n to this named node map.
|
---|
2693 | */
|
---|
2694 | QDomNamedNodeMap& QDomNamedNodeMap::operator= ( const QDomNamedNodeMap& n )
|
---|
2695 | {
|
---|
2696 | if ( impl && impl->deref() )
|
---|
2697 | delete impl;
|
---|
2698 | impl = n.impl;
|
---|
2699 | if ( impl )
|
---|
2700 | impl->ref();
|
---|
2701 |
|
---|
2702 | return *this;
|
---|
2703 | }
|
---|
2704 |
|
---|
2705 | /*!
|
---|
2706 | Returns TRUE if \a n and this named node map are equal; otherwise
|
---|
2707 | returns FALSE.
|
---|
2708 | */
|
---|
2709 | bool QDomNamedNodeMap::operator== ( const QDomNamedNodeMap& n ) const
|
---|
2710 | {
|
---|
2711 | return ( impl == n.impl );
|
---|
2712 | }
|
---|
2713 |
|
---|
2714 | /*!
|
---|
2715 | Returns TRUE if \a n and this named node map are not equal;
|
---|
2716 | otherwise returns FALSE.
|
---|
2717 | */
|
---|
2718 | bool QDomNamedNodeMap::operator!= ( const QDomNamedNodeMap& n ) const
|
---|
2719 | {
|
---|
2720 | return ( impl != n.impl );
|
---|
2721 | }
|
---|
2722 |
|
---|
2723 | /*!
|
---|
2724 | Destroys the object and frees its resources.
|
---|
2725 | */
|
---|
2726 | QDomNamedNodeMap::~QDomNamedNodeMap()
|
---|
2727 | {
|
---|
2728 | if ( impl && impl->deref() )
|
---|
2729 | delete impl;
|
---|
2730 | }
|
---|
2731 |
|
---|
2732 | /*!
|
---|
2733 | Returns the node called \a name.
|
---|
2734 |
|
---|
2735 | If the named node map does not contain such a node, a \link
|
---|
2736 | QDomNode::isNull() null node\endlink is returned. A node's name is
|
---|
2737 | the name returned by QDomNode::nodeName().
|
---|
2738 |
|
---|
2739 | \sa setNamedItem() namedItemNS()
|
---|
2740 | */
|
---|
2741 | QDomNode QDomNamedNodeMap::namedItem( const QString& name ) const
|
---|
2742 | {
|
---|
2743 | if ( !impl )
|
---|
2744 | return QDomNode();
|
---|
2745 | return QDomNode( IMPL->namedItem( name ) );
|
---|
2746 | }
|
---|
2747 |
|
---|
2748 | /*!
|
---|
2749 | Inserts the node \a newNode into the named node map. The name used
|
---|
2750 | by the map is the node name of \a newNode as returned by
|
---|
2751 | QDomNode::nodeName().
|
---|
2752 |
|
---|
2753 | If the new node replaces an existing node, i.e. the map contains a
|
---|
2754 | node with the same name, the replaced node is returned.
|
---|
2755 |
|
---|
2756 | \sa namedItem() removeNamedItem() setNamedItemNS()
|
---|
2757 | */
|
---|
2758 | QDomNode QDomNamedNodeMap::setNamedItem( const QDomNode& newNode )
|
---|
2759 | {
|
---|
2760 | if ( !impl )
|
---|
2761 | return QDomNode();
|
---|
2762 | return QDomNode( IMPL->setNamedItem( (QDomNodePrivate*)newNode.impl ) );
|
---|
2763 | }
|
---|
2764 |
|
---|
2765 | /*!
|
---|
2766 | Removes the node called \a name from the map.
|
---|
2767 |
|
---|
2768 | The function returns the removed node or a \link
|
---|
2769 | QDomNode::isNull() null node\endlink if the map did not contain a
|
---|
2770 | node called \a name.
|
---|
2771 |
|
---|
2772 | \sa setNamedItem() namedItem() removeNamedItemNS()
|
---|
2773 | */
|
---|
2774 | QDomNode QDomNamedNodeMap::removeNamedItem( const QString& name )
|
---|
2775 | {
|
---|
2776 | if ( !impl )
|
---|
2777 | return QDomNode();
|
---|
2778 | return QDomNode( IMPL->removeNamedItem( name ) );
|
---|
2779 | }
|
---|
2780 |
|
---|
2781 | /*!
|
---|
2782 | Retrieves the node at position \a index.
|
---|
2783 |
|
---|
2784 | This can be used to iterate over the map. Note that the nodes in
|
---|
2785 | the map are ordered arbitrarily.
|
---|
2786 |
|
---|
2787 | \sa length()
|
---|
2788 | */
|
---|
2789 | QDomNode QDomNamedNodeMap::item( int index ) const
|
---|
2790 | {
|
---|
2791 | if ( !impl )
|
---|
2792 | return QDomNode();
|
---|
2793 | return QDomNode( IMPL->item( index ) );
|
---|
2794 | }
|
---|
2795 |
|
---|
2796 | /*!
|
---|
2797 | Returns the node associated with the local name \a localName and
|
---|
2798 | the namespace URI \a nsURI.
|
---|
2799 |
|
---|
2800 | If the map does not contain such a node, a \link
|
---|
2801 | QDomNode::isNull() null node\endlink is returned.
|
---|
2802 |
|
---|
2803 | \sa setNamedItemNS() namedItem()
|
---|
2804 | */
|
---|
2805 | QDomNode QDomNamedNodeMap::namedItemNS( const QString& nsURI, const QString& localName ) const
|
---|
2806 | {
|
---|
2807 | if ( !impl )
|
---|
2808 | return QDomNode();
|
---|
2809 | return QDomNode( IMPL->namedItemNS( nsURI, localName ) );
|
---|
2810 | }
|
---|
2811 |
|
---|
2812 | /*!
|
---|
2813 | Inserts the node \a newNode in the map. If a node with the same
|
---|
2814 | namespace URI and the same local name already exists in the map,
|
---|
2815 | it is replaced by \a newNode. If the new node replaces an existing
|
---|
2816 | node, the replaced node is returned.
|
---|
2817 |
|
---|
2818 | \sa namedItemNS() removeNamedItemNS() setNamedItem()
|
---|
2819 | */
|
---|
2820 | QDomNode QDomNamedNodeMap::setNamedItemNS( const QDomNode& newNode )
|
---|
2821 | {
|
---|
2822 | if ( !impl )
|
---|
2823 | return QDomNode();
|
---|
2824 | return QDomNode( IMPL->setNamedItemNS( (QDomNodePrivate*)newNode.impl ) );
|
---|
2825 | }
|
---|
2826 |
|
---|
2827 | /*!
|
---|
2828 | Removes the node with the local name \a localName and the
|
---|
2829 | namespace URI \a nsURI from the map.
|
---|
2830 |
|
---|
2831 | The function returns the removed node or a \link
|
---|
2832 | QDomNode::isNull() null node\endlink if the map did not contain a
|
---|
2833 | node with the local name \a localName and the namespace URI \a
|
---|
2834 | nsURI.
|
---|
2835 |
|
---|
2836 | \sa setNamedItemNS() namedItemNS() removeNamedItem()
|
---|
2837 | */
|
---|
2838 | QDomNode QDomNamedNodeMap::removeNamedItemNS( const QString& nsURI, const QString& localName )
|
---|
2839 | {
|
---|
2840 | if ( !impl )
|
---|
2841 | return QDomNode();
|
---|
2842 | QDomNodePrivate *n = IMPL->namedItemNS( nsURI, localName );
|
---|
2843 | if ( !n )
|
---|
2844 | return QDomNode();
|
---|
2845 | return QDomNode( IMPL->removeNamedItem( n->name ) );
|
---|
2846 | }
|
---|
2847 |
|
---|
2848 | /*!
|
---|
2849 | Returns the number of nodes in the map.
|
---|
2850 |
|
---|
2851 | \sa item()
|
---|
2852 | */
|
---|
2853 | uint QDomNamedNodeMap::length() const
|
---|
2854 | {
|
---|
2855 | if ( !impl )
|
---|
2856 | return 0;
|
---|
2857 | return IMPL->length();
|
---|
2858 | }
|
---|
2859 |
|
---|
2860 | /*!
|
---|
2861 | \fn uint QDomNamedNodeMap::count() const
|
---|
2862 |
|
---|
2863 | Returns the number of nodes in the map.
|
---|
2864 |
|
---|
2865 | This function is the same as length().
|
---|
2866 | */
|
---|
2867 |
|
---|
2868 | /*!
|
---|
2869 | Returns TRUE if the map contains a node called \a name; otherwise
|
---|
2870 | returns FALSE.
|
---|
2871 | */
|
---|
2872 | bool QDomNamedNodeMap::contains( const QString& name ) const
|
---|
2873 | {
|
---|
2874 | if ( !impl )
|
---|
2875 | return FALSE;
|
---|
2876 | return IMPL->contains( name );
|
---|
2877 | }
|
---|
2878 |
|
---|
2879 | #undef IMPL
|
---|
2880 |
|
---|
2881 | /**************************************************************
|
---|
2882 | *
|
---|
2883 | * QDomDocumentTypePrivate
|
---|
2884 | *
|
---|
2885 | **************************************************************/
|
---|
2886 |
|
---|
2887 | QDomDocumentTypePrivate::QDomDocumentTypePrivate( QDomDocumentPrivate* doc, QDomNodePrivate* parent )
|
---|
2888 | : QDomNodePrivate( doc, parent )
|
---|
2889 | {
|
---|
2890 | init();
|
---|
2891 | }
|
---|
2892 |
|
---|
2893 | QDomDocumentTypePrivate::QDomDocumentTypePrivate( QDomDocumentTypePrivate* n, bool deep )
|
---|
2894 | : QDomNodePrivate( n, deep )
|
---|
2895 | {
|
---|
2896 | init();
|
---|
2897 | // Refill the maps with our new children
|
---|
2898 | QDomNodePrivate* p = first;
|
---|
2899 | while ( p ) {
|
---|
2900 | if ( p->isEntity() )
|
---|
2901 | // Dont use normal insert function since we would create infinite recursion
|
---|
2902 | entities->map.insert( p->nodeName(), p );
|
---|
2903 | if ( p->isNotation() )
|
---|
2904 | // Dont use normal insert function since we would create infinite recursion
|
---|
2905 | notations->map.insert( p->nodeName(), p );
|
---|
2906 | }
|
---|
2907 | }
|
---|
2908 |
|
---|
2909 | QDomDocumentTypePrivate::~QDomDocumentTypePrivate()
|
---|
2910 | {
|
---|
2911 | if ( entities->deref() )
|
---|
2912 | delete entities;
|
---|
2913 | if ( notations->deref() )
|
---|
2914 | delete notations;
|
---|
2915 | }
|
---|
2916 |
|
---|
2917 | void QDomDocumentTypePrivate::init()
|
---|
2918 | {
|
---|
2919 | entities = new QDomNamedNodeMapPrivate( this );
|
---|
2920 | notations = new QDomNamedNodeMapPrivate( this );
|
---|
2921 | publicId = QString::null;
|
---|
2922 | systemId = QString::null;
|
---|
2923 | internalSubset = QString::null;
|
---|
2924 |
|
---|
2925 | entities->setAppendToParent( TRUE );
|
---|
2926 | notations->setAppendToParent( TRUE );
|
---|
2927 | }
|
---|
2928 |
|
---|
2929 | QDomNodePrivate* QDomDocumentTypePrivate::cloneNode( bool deep)
|
---|
2930 | {
|
---|
2931 | QDomNodePrivate* p = new QDomDocumentTypePrivate( this, deep );
|
---|
2932 | // We are not interested in this node
|
---|
2933 | p->deref();
|
---|
2934 | return p;
|
---|
2935 | }
|
---|
2936 |
|
---|
2937 | QDomNodePrivate* QDomDocumentTypePrivate::insertBefore( QDomNodePrivate* newChild, QDomNodePrivate* refChild )
|
---|
2938 | {
|
---|
2939 | // Call the origianl implementation
|
---|
2940 | QDomNodePrivate* p = QDomNodePrivate::insertBefore( newChild, refChild );
|
---|
2941 | // Update the maps
|
---|
2942 | if ( p && p->isEntity() )
|
---|
2943 | entities->map.insert( p->nodeName(), p );
|
---|
2944 | else if ( p && p->isNotation() )
|
---|
2945 | notations->map.insert( p->nodeName(), p );
|
---|
2946 |
|
---|
2947 | return p;
|
---|
2948 | }
|
---|
2949 |
|
---|
2950 | QDomNodePrivate* QDomDocumentTypePrivate::insertAfter( QDomNodePrivate* newChild, QDomNodePrivate* refChild )
|
---|
2951 | {
|
---|
2952 | // Call the origianl implementation
|
---|
2953 | QDomNodePrivate* p = QDomNodePrivate::insertAfter( newChild, refChild );
|
---|
2954 | // Update the maps
|
---|
2955 | if ( p && p->isEntity() )
|
---|
2956 | entities->map.insert( p->nodeName(), p );
|
---|
2957 | else if ( p && p->isNotation() )
|
---|
2958 | notations->map.insert( p->nodeName(), p );
|
---|
2959 |
|
---|
2960 | return p;
|
---|
2961 | }
|
---|
2962 |
|
---|
2963 | QDomNodePrivate* QDomDocumentTypePrivate::replaceChild( QDomNodePrivate* newChild, QDomNodePrivate* oldChild )
|
---|
2964 | {
|
---|
2965 | // Call the origianl implementation
|
---|
2966 | QDomNodePrivate* p = QDomNodePrivate::replaceChild( newChild, oldChild );
|
---|
2967 | // Update the maps
|
---|
2968 | if ( p ) {
|
---|
2969 | if ( oldChild && oldChild->isEntity() )
|
---|
2970 | entities->map.remove( oldChild->nodeName() );
|
---|
2971 | else if ( oldChild && oldChild->isNotation() )
|
---|
2972 | notations->map.remove( oldChild->nodeName() );
|
---|
2973 |
|
---|
2974 | if ( p->isEntity() )
|
---|
2975 | entities->map.insert( p->nodeName(), p );
|
---|
2976 | else if ( p->isNotation() )
|
---|
2977 | notations->map.insert( p->nodeName(), p );
|
---|
2978 | }
|
---|
2979 |
|
---|
2980 | return p;
|
---|
2981 | }
|
---|
2982 |
|
---|
2983 | QDomNodePrivate* QDomDocumentTypePrivate::removeChild( QDomNodePrivate* oldChild )
|
---|
2984 | {
|
---|
2985 | // Call the origianl implementation
|
---|
2986 | QDomNodePrivate* p = QDomNodePrivate::removeChild( oldChild );
|
---|
2987 | // Update the maps
|
---|
2988 | if ( p && p->isEntity() )
|
---|
2989 | entities->map.remove( p->nodeName() );
|
---|
2990 | else if ( p && p->isNotation() )
|
---|
2991 | notations->map.remove( p ->nodeName() );
|
---|
2992 |
|
---|
2993 | return p;
|
---|
2994 | }
|
---|
2995 |
|
---|
2996 | QDomNodePrivate* QDomDocumentTypePrivate::appendChild( QDomNodePrivate* newChild )
|
---|
2997 | {
|
---|
2998 | return insertAfter( newChild, 0 );
|
---|
2999 | }
|
---|
3000 |
|
---|
3001 | void QDomDocumentTypePrivate::save( QTextStream& s, int, int indent ) const
|
---|
3002 | {
|
---|
3003 | if ( name.isEmpty() )
|
---|
3004 | return;
|
---|
3005 |
|
---|
3006 | s << "<!DOCTYPE " << name;
|
---|
3007 |
|
---|
3008 | if ( !publicId.isNull() ) {
|
---|
3009 | s << " PUBLIC \"" << publicId << "\"";
|
---|
3010 | if ( !systemId.isNull() )
|
---|
3011 | s << " \"" << systemId << "\"";
|
---|
3012 | } else if ( !systemId.isNull() ) {
|
---|
3013 | s << " SYSTEM \"" << systemId << "\"";
|
---|
3014 | }
|
---|
3015 |
|
---|
3016 | if ( entities->length()>0 || notations->length()>0 ) {
|
---|
3017 | s << " [ " << endl;
|
---|
3018 |
|
---|
3019 | QDictIterator<QDomNodePrivate> it2( notations->map );
|
---|
3020 | for ( ; it2.current(); ++it2 )
|
---|
3021 | it2.current()->save( s, 0, indent );
|
---|
3022 |
|
---|
3023 | QDictIterator<QDomNodePrivate> it( entities->map );
|
---|
3024 | for ( ; it.current(); ++it )
|
---|
3025 | it.current()->save( s, 0, indent );
|
---|
3026 |
|
---|
3027 | s << " ]";
|
---|
3028 | }
|
---|
3029 |
|
---|
3030 | s << ">" << endl;
|
---|
3031 | }
|
---|
3032 |
|
---|
3033 | /**************************************************************
|
---|
3034 | *
|
---|
3035 | * QDomDocumentType
|
---|
3036 | *
|
---|
3037 | **************************************************************/
|
---|
3038 |
|
---|
3039 | #define IMPL ((QDomDocumentTypePrivate*)impl)
|
---|
3040 |
|
---|
3041 | /*!
|
---|
3042 | \class QDomDocumentType qdom.h
|
---|
3043 | \reentrant
|
---|
3044 | \brief The QDomDocumentType class is the representation of the DTD
|
---|
3045 | in the document tree.
|
---|
3046 | \if defined(commercial)
|
---|
3047 | It is part of the <a href="commercialeditions.html">Qt Enterprise Edition</a>.
|
---|
3048 | \endif
|
---|
3049 |
|
---|
3050 | \module XML
|
---|
3051 | \ingroup xml-tools
|
---|
3052 |
|
---|
3053 | The QDomDocumentType class allows read-only access to some of the
|
---|
3054 | data structures in the DTD: it can return a map of all entities()
|
---|
3055 | and notations(). In addition the function name() returns the name
|
---|
3056 | of the document type as specified in the <!DOCTYPE name>
|
---|
3057 | tag. This class also provides the publicId(), systemId() and
|
---|
3058 | internalSubset() functions.
|
---|
3059 |
|
---|
3060 | \sa QDomDocument
|
---|
3061 | */
|
---|
3062 |
|
---|
3063 | /*!
|
---|
3064 | Creates an empty QDomDocumentType object.
|
---|
3065 | */
|
---|
3066 | QDomDocumentType::QDomDocumentType() : QDomNode()
|
---|
3067 | {
|
---|
3068 | }
|
---|
3069 |
|
---|
3070 | /*!
|
---|
3071 | Constructs a copy of \a n.
|
---|
3072 |
|
---|
3073 | The data of the copy is shared (shallow copy): modifying one node
|
---|
3074 | will also change the other. If you want to make a deep copy, use
|
---|
3075 | cloneNode().
|
---|
3076 | */
|
---|
3077 | QDomDocumentType::QDomDocumentType( const QDomDocumentType& n )
|
---|
3078 | : QDomNode( n )
|
---|
3079 | {
|
---|
3080 | }
|
---|
3081 |
|
---|
3082 | QDomDocumentType::QDomDocumentType( QDomDocumentTypePrivate* n )
|
---|
3083 | : QDomNode( n )
|
---|
3084 | {
|
---|
3085 | }
|
---|
3086 |
|
---|
3087 | /*!
|
---|
3088 | Assigns \a n to this document type.
|
---|
3089 |
|
---|
3090 | The data of the copy is shared (shallow copy): modifying one node
|
---|
3091 | will also change the other. If you want to make a deep copy, use
|
---|
3092 | cloneNode().
|
---|
3093 | */
|
---|
3094 | QDomDocumentType& QDomDocumentType::operator= ( const QDomDocumentType& n )
|
---|
3095 | {
|
---|
3096 | return (QDomDocumentType&) QDomNode::operator=( n );
|
---|
3097 | }
|
---|
3098 |
|
---|
3099 | /*!
|
---|
3100 | Destroys the object and frees its resources.
|
---|
3101 | */
|
---|
3102 | QDomDocumentType::~QDomDocumentType()
|
---|
3103 | {
|
---|
3104 | }
|
---|
3105 |
|
---|
3106 | /*!
|
---|
3107 | Returns the name of the document type as specified in the
|
---|
3108 | <!DOCTYPE name> tag.
|
---|
3109 |
|
---|
3110 | \sa nodeName()
|
---|
3111 | */
|
---|
3112 | QString QDomDocumentType::name() const
|
---|
3113 | {
|
---|
3114 | if ( !impl )
|
---|
3115 | return QString::null;
|
---|
3116 |
|
---|
3117 | return IMPL->nodeName();
|
---|
3118 | }
|
---|
3119 |
|
---|
3120 | /*!
|
---|
3121 | Returns a map of all entities described in the DTD.
|
---|
3122 | */
|
---|
3123 | QDomNamedNodeMap QDomDocumentType::entities() const
|
---|
3124 | {
|
---|
3125 | if ( !impl )
|
---|
3126 | return QDomNamedNodeMap();
|
---|
3127 | return QDomNamedNodeMap( IMPL->entities );
|
---|
3128 | }
|
---|
3129 |
|
---|
3130 | /*!
|
---|
3131 | Returns a map of all notations described in the DTD.
|
---|
3132 | */
|
---|
3133 | QDomNamedNodeMap QDomDocumentType::notations() const
|
---|
3134 | {
|
---|
3135 | if ( !impl )
|
---|
3136 | return QDomNamedNodeMap();
|
---|
3137 | return QDomNamedNodeMap( IMPL->notations );
|
---|
3138 | }
|
---|
3139 |
|
---|
3140 | /*!
|
---|
3141 | Returns the public identifier of the external DTD subset or
|
---|
3142 | QString::null if there is no public identifier.
|
---|
3143 |
|
---|
3144 | \sa systemId() internalSubset() QDomImplementation::createDocumentType()
|
---|
3145 | */
|
---|
3146 | QString QDomDocumentType::publicId() const
|
---|
3147 | {
|
---|
3148 | if ( !impl )
|
---|
3149 | return QString::null;
|
---|
3150 | return IMPL->publicId;
|
---|
3151 | }
|
---|
3152 |
|
---|
3153 | /*!
|
---|
3154 | Returns the system identifier of the external DTD subset or
|
---|
3155 | QString::null if there is no system identifier.
|
---|
3156 |
|
---|
3157 | \sa publicId() internalSubset() QDomImplementation::createDocumentType()
|
---|
3158 | */
|
---|
3159 | QString QDomDocumentType::systemId() const
|
---|
3160 | {
|
---|
3161 | if ( !impl )
|
---|
3162 | return QString::null;
|
---|
3163 | return IMPL->systemId;
|
---|
3164 | }
|
---|
3165 |
|
---|
3166 | /*!
|
---|
3167 | Returns the internal subset of the document type or QString::null
|
---|
3168 | if there is no internal subset.
|
---|
3169 |
|
---|
3170 | \sa publicId() systemId()
|
---|
3171 | */
|
---|
3172 | QString QDomDocumentType::internalSubset() const
|
---|
3173 | {
|
---|
3174 | if ( !impl )
|
---|
3175 | return QString::null;
|
---|
3176 | return IMPL->internalSubset;
|
---|
3177 | }
|
---|
3178 |
|
---|
3179 | /*!
|
---|
3180 | Returns \c DocumentTypeNode.
|
---|
3181 |
|
---|
3182 | \sa isDocumentType() QDomNode::toDocumentType()
|
---|
3183 | */
|
---|
3184 | QDomNode::NodeType QDomDocumentType::nodeType() const
|
---|
3185 | {
|
---|
3186 | return DocumentTypeNode;
|
---|
3187 | }
|
---|
3188 |
|
---|
3189 | /*!
|
---|
3190 | This function overloads QDomNode::isDocumentType().
|
---|
3191 |
|
---|
3192 | \sa nodeType() QDomNode::toDocumentType()
|
---|
3193 | */
|
---|
3194 | bool QDomDocumentType::isDocumentType() const
|
---|
3195 | {
|
---|
3196 | return TRUE;
|
---|
3197 | }
|
---|
3198 |
|
---|
3199 | #undef IMPL
|
---|
3200 |
|
---|
3201 | /**************************************************************
|
---|
3202 | *
|
---|
3203 | * QDomDocumentFragmentPrivate
|
---|
3204 | *
|
---|
3205 | **************************************************************/
|
---|
3206 |
|
---|
3207 | QDomDocumentFragmentPrivate::QDomDocumentFragmentPrivate( QDomDocumentPrivate* doc, QDomNodePrivate* parent )
|
---|
3208 | : QDomNodePrivate( doc, parent )
|
---|
3209 | {
|
---|
3210 | name = "#document-fragment";
|
---|
3211 | }
|
---|
3212 |
|
---|
3213 | QDomDocumentFragmentPrivate::QDomDocumentFragmentPrivate( QDomNodePrivate* n, bool deep )
|
---|
3214 | : QDomNodePrivate( n, deep )
|
---|
3215 | {
|
---|
3216 | }
|
---|
3217 |
|
---|
3218 | QDomDocumentFragmentPrivate::~QDomDocumentFragmentPrivate()
|
---|
3219 | {
|
---|
3220 | }
|
---|
3221 |
|
---|
3222 | QDomNodePrivate* QDomDocumentFragmentPrivate::cloneNode( bool deep)
|
---|
3223 | {
|
---|
3224 | QDomNodePrivate* p = new QDomDocumentFragmentPrivate( this, deep );
|
---|
3225 | // We are not interested in this node
|
---|
3226 | p->deref();
|
---|
3227 | return p;
|
---|
3228 | }
|
---|
3229 |
|
---|
3230 | /**************************************************************
|
---|
3231 | *
|
---|
3232 | * QDomDocumentFragment
|
---|
3233 | *
|
---|
3234 | **************************************************************/
|
---|
3235 |
|
---|
3236 | #define IMPL ((QDomDocumentFragmentPrivate*)impl)
|
---|
3237 |
|
---|
3238 | /*!
|
---|
3239 | \class QDomDocumentFragment qdom.h
|
---|
3240 | \reentrant
|
---|
3241 | \brief The QDomDocumentFragment class is a tree of QDomNodes which is not usually a complete QDomDocument.
|
---|
3242 | \if defined(commercial)
|
---|
3243 | It is part of the <a href="commercialeditions.html">Qt Enterprise Edition</a>.
|
---|
3244 | \endif
|
---|
3245 |
|
---|
3246 | \module XML
|
---|
3247 | \ingroup xml-tools
|
---|
3248 |
|
---|
3249 | If you want to do complex tree operations it is useful to have a
|
---|
3250 | lightweight class to store nodes and their relations.
|
---|
3251 | QDomDocumentFragment stores a subtree of a document which does not
|
---|
3252 | necessarily represent a well-formed XML document.
|
---|
3253 |
|
---|
3254 | QDomDocumentFragment is also useful if you want to group several
|
---|
3255 | nodes in a list and insert them all together as children of some
|
---|
3256 | node. In these cases QDomDocumentFragment can be used as a
|
---|
3257 | temporary container for this list of children.
|
---|
3258 |
|
---|
3259 | The most important feature of QDomDocumentFragment is that it is
|
---|
3260 | treated in a special way by QDomNode::insertAfter(),
|
---|
3261 | QDomNode::insertBefore(), QDomNode::replaceChild() and
|
---|
3262 | QDomNode::appendChild(): instead of inserting the fragment itself, all
|
---|
3263 | the fragment's children are inserted.
|
---|
3264 | */
|
---|
3265 |
|
---|
3266 | /*!
|
---|
3267 | Constructs an empty document fragment.
|
---|
3268 | */
|
---|
3269 | QDomDocumentFragment::QDomDocumentFragment()
|
---|
3270 | {
|
---|
3271 | }
|
---|
3272 |
|
---|
3273 | QDomDocumentFragment::QDomDocumentFragment( QDomDocumentFragmentPrivate* n )
|
---|
3274 | : QDomNode( n )
|
---|
3275 | {
|
---|
3276 | }
|
---|
3277 |
|
---|
3278 | /*!
|
---|
3279 | Constructs a copy of \a x.
|
---|
3280 |
|
---|
3281 | The data of the copy is shared (shallow copy): modifying one node
|
---|
3282 | will also change the other. If you want to make a deep copy, use
|
---|
3283 | cloneNode().
|
---|
3284 | */
|
---|
3285 | QDomDocumentFragment::QDomDocumentFragment( const QDomDocumentFragment& x )
|
---|
3286 | : QDomNode( x )
|
---|
3287 | {
|
---|
3288 | }
|
---|
3289 |
|
---|
3290 | /*!
|
---|
3291 | Assigns \a x to this DOM document fragment.
|
---|
3292 |
|
---|
3293 | The data of the copy is shared (shallow copy): modifying one node
|
---|
3294 | will also change the other. If you want to make a deep copy, use
|
---|
3295 | cloneNode().
|
---|
3296 | */
|
---|
3297 | QDomDocumentFragment& QDomDocumentFragment::operator= ( const QDomDocumentFragment& x )
|
---|
3298 | {
|
---|
3299 | return (QDomDocumentFragment&) QDomNode::operator=( x );
|
---|
3300 | }
|
---|
3301 |
|
---|
3302 | /*!
|
---|
3303 | Destroys the object and frees its resources.
|
---|
3304 | */
|
---|
3305 | QDomDocumentFragment::~QDomDocumentFragment()
|
---|
3306 | {
|
---|
3307 | }
|
---|
3308 |
|
---|
3309 | /*!
|
---|
3310 | Returns \c DocumentFragment.
|
---|
3311 |
|
---|
3312 | \sa isDocumentFragment() QDomNode::toDocumentFragment()
|
---|
3313 | */
|
---|
3314 | QDomNode::NodeType QDomDocumentFragment::nodeType() const
|
---|
3315 | {
|
---|
3316 | return QDomNode::DocumentFragmentNode;
|
---|
3317 | }
|
---|
3318 |
|
---|
3319 | /*!
|
---|
3320 | This function reimplements QDomNode::isDocumentFragment().
|
---|
3321 |
|
---|
3322 | \sa nodeType() QDomNode::toDocumentFragment()
|
---|
3323 | */
|
---|
3324 | bool QDomDocumentFragment::isDocumentFragment() const
|
---|
3325 | {
|
---|
3326 | return TRUE;
|
---|
3327 | }
|
---|
3328 |
|
---|
3329 | #undef IMPL
|
---|
3330 |
|
---|
3331 | /**************************************************************
|
---|
3332 | *
|
---|
3333 | * QDomCharacterDataPrivate
|
---|
3334 | *
|
---|
3335 | **************************************************************/
|
---|
3336 |
|
---|
3337 | QDomCharacterDataPrivate::QDomCharacterDataPrivate( QDomDocumentPrivate* d, QDomNodePrivate* p,
|
---|
3338 | const QString& data )
|
---|
3339 | : QDomNodePrivate( d, p )
|
---|
3340 | {
|
---|
3341 | value = data;
|
---|
3342 |
|
---|
3343 | name = "#character-data";
|
---|
3344 | }
|
---|
3345 |
|
---|
3346 | QDomCharacterDataPrivate::QDomCharacterDataPrivate( QDomCharacterDataPrivate* n, bool deep )
|
---|
3347 | : QDomNodePrivate( n, deep )
|
---|
3348 | {
|
---|
3349 | }
|
---|
3350 |
|
---|
3351 | QDomCharacterDataPrivate::~QDomCharacterDataPrivate()
|
---|
3352 | {
|
---|
3353 | }
|
---|
3354 |
|
---|
3355 | QDomNodePrivate* QDomCharacterDataPrivate::cloneNode( bool deep )
|
---|
3356 | {
|
---|
3357 | QDomNodePrivate* p = new QDomCharacterDataPrivate( this, deep );
|
---|
3358 | // We are not interested in this node
|
---|
3359 | p->deref();
|
---|
3360 | return p;
|
---|
3361 | }
|
---|
3362 |
|
---|
3363 | uint QDomCharacterDataPrivate::dataLength() const
|
---|
3364 | {
|
---|
3365 | return value.length();
|
---|
3366 | }
|
---|
3367 |
|
---|
3368 | QString QDomCharacterDataPrivate::substringData( unsigned long offset, unsigned long n ) const
|
---|
3369 | {
|
---|
3370 | return value.mid( offset, n );
|
---|
3371 | }
|
---|
3372 |
|
---|
3373 | void QDomCharacterDataPrivate::insertData( unsigned long offset, const QString& arg )
|
---|
3374 | {
|
---|
3375 | value.insert( offset, arg );
|
---|
3376 | }
|
---|
3377 |
|
---|
3378 | void QDomCharacterDataPrivate::deleteData( unsigned long offset, unsigned long n )
|
---|
3379 | {
|
---|
3380 | value.remove( offset, n );
|
---|
3381 | }
|
---|
3382 |
|
---|
3383 | void QDomCharacterDataPrivate::replaceData( unsigned long offset, unsigned long n, const QString& arg )
|
---|
3384 | {
|
---|
3385 | value.replace( offset, n, arg );
|
---|
3386 | }
|
---|
3387 |
|
---|
3388 | void QDomCharacterDataPrivate::appendData( const QString& arg )
|
---|
3389 | {
|
---|
3390 | value += arg;
|
---|
3391 | }
|
---|
3392 |
|
---|
3393 | /**************************************************************
|
---|
3394 | *
|
---|
3395 | * QDomCharacterData
|
---|
3396 | *
|
---|
3397 | **************************************************************/
|
---|
3398 |
|
---|
3399 | #define IMPL ((QDomCharacterDataPrivate*)impl)
|
---|
3400 |
|
---|
3401 | /*!
|
---|
3402 | \class QDomCharacterData qdom.h
|
---|
3403 | \reentrant
|
---|
3404 | \brief The QDomCharacterData class represents a generic string in the DOM.
|
---|
3405 | \if defined(commercial)
|
---|
3406 | It is part of the <a href="commercialeditions.html">Qt Enterprise Edition</a>.
|
---|
3407 | \endif
|
---|
3408 |
|
---|
3409 | \module XML
|
---|
3410 | \ingroup xml-tools
|
---|
3411 |
|
---|
3412 | Character data as used in XML specifies a generic data string.
|
---|
3413 | More specialized versions of this class are QDomText, QDomComment
|
---|
3414 | and QDomCDATASection.
|
---|
3415 |
|
---|
3416 | The data string is set with setData() and retrieved with data().
|
---|
3417 | You can retrieve a portion of the data string using
|
---|
3418 | substringData(). Extra data can be appended with appendData(), or
|
---|
3419 | inserted with insertData(). Portions of the data string can be
|
---|
3420 | deleted with deleteData() or replaced with replaceData(). The
|
---|
3421 | length of the data string is returned by length().
|
---|
3422 |
|
---|
3423 | The node type of the node containing this character data is
|
---|
3424 | returned by nodeType().
|
---|
3425 |
|
---|
3426 | \sa QDomText QDomComment QDomCDATASection
|
---|
3427 | */
|
---|
3428 |
|
---|
3429 | /*!
|
---|
3430 | Constructs an empty character data object.
|
---|
3431 | */
|
---|
3432 | QDomCharacterData::QDomCharacterData()
|
---|
3433 | {
|
---|
3434 | }
|
---|
3435 |
|
---|
3436 | /*!
|
---|
3437 | Constructs a copy of \a x.
|
---|
3438 |
|
---|
3439 | The data of the copy is shared (shallow copy): modifying one node
|
---|
3440 | will also change the other. If you want to make a deep copy, use
|
---|
3441 | cloneNode().
|
---|
3442 | */
|
---|
3443 | QDomCharacterData::QDomCharacterData( const QDomCharacterData& x )
|
---|
3444 | : QDomNode( x )
|
---|
3445 | {
|
---|
3446 | }
|
---|
3447 |
|
---|
3448 | QDomCharacterData::QDomCharacterData( QDomCharacterDataPrivate* n )
|
---|
3449 | : QDomNode( n )
|
---|
3450 | {
|
---|
3451 | }
|
---|
3452 |
|
---|
3453 | /*!
|
---|
3454 | Assigns \a x to this character data.
|
---|
3455 |
|
---|
3456 | The data of the copy is shared (shallow copy): modifying one node
|
---|
3457 | will also change the other. If you want to make a deep copy, use
|
---|
3458 | cloneNode().
|
---|
3459 | */
|
---|
3460 | QDomCharacterData& QDomCharacterData::operator= ( const QDomCharacterData& x )
|
---|
3461 | {
|
---|
3462 | return (QDomCharacterData&) QDomNode::operator=( x );
|
---|
3463 | }
|
---|
3464 |
|
---|
3465 | /*!
|
---|
3466 | Destroys the object and frees its resources.
|
---|
3467 | */
|
---|
3468 | QDomCharacterData::~QDomCharacterData()
|
---|
3469 | {
|
---|
3470 | }
|
---|
3471 |
|
---|
3472 | /*!
|
---|
3473 | Returns the string stored in this object.
|
---|
3474 |
|
---|
3475 | If the node is a \link isNull() null node\endlink, it will return
|
---|
3476 | QString::null.
|
---|
3477 | */
|
---|
3478 | QString QDomCharacterData::data() const
|
---|
3479 | {
|
---|
3480 | if ( !impl )
|
---|
3481 | return QString::null;
|
---|
3482 | return impl->nodeValue();
|
---|
3483 | }
|
---|
3484 |
|
---|
3485 | /*!
|
---|
3486 | Sets this object's string to \a v.
|
---|
3487 | */
|
---|
3488 | void QDomCharacterData::setData( const QString& v )
|
---|
3489 | {
|
---|
3490 | if ( impl )
|
---|
3491 | impl->setNodeValue( v );
|
---|
3492 | }
|
---|
3493 |
|
---|
3494 | /*!
|
---|
3495 | Returns the length of the stored string.
|
---|
3496 | */
|
---|
3497 | uint QDomCharacterData::length() const
|
---|
3498 | {
|
---|
3499 | if ( impl )
|
---|
3500 | return IMPL->dataLength();
|
---|
3501 | return 0;
|
---|
3502 | }
|
---|
3503 |
|
---|
3504 | /*!
|
---|
3505 | Returns the substring of length \a count from position \a offset.
|
---|
3506 | */
|
---|
3507 | QString QDomCharacterData::substringData( unsigned long offset, unsigned long count )
|
---|
3508 | {
|
---|
3509 | if ( !impl )
|
---|
3510 | return QString::null;
|
---|
3511 | return IMPL->substringData( offset, count );
|
---|
3512 | }
|
---|
3513 |
|
---|
3514 | /*!
|
---|
3515 | Appends the string \a arg to the stored string.
|
---|
3516 | */
|
---|
3517 | void QDomCharacterData::appendData( const QString& arg )
|
---|
3518 | {
|
---|
3519 | if ( impl )
|
---|
3520 | IMPL->appendData( arg );
|
---|
3521 | }
|
---|
3522 |
|
---|
3523 | /*!
|
---|
3524 | Inserts the string \a arg into the stored string at position \a offset.
|
---|
3525 | */
|
---|
3526 | void QDomCharacterData::insertData( unsigned long offset, const QString& arg )
|
---|
3527 | {
|
---|
3528 | if ( impl )
|
---|
3529 | IMPL->insertData( offset, arg );
|
---|
3530 | }
|
---|
3531 |
|
---|
3532 | /*!
|
---|
3533 | Deletes a substring of length \a count from position \a offset.
|
---|
3534 | */
|
---|
3535 | void QDomCharacterData::deleteData( unsigned long offset, unsigned long count )
|
---|
3536 | {
|
---|
3537 | if ( impl )
|
---|
3538 | IMPL->deleteData( offset, count );
|
---|
3539 | }
|
---|
3540 |
|
---|
3541 | /*!
|
---|
3542 | Replaces the substring of length \a count starting at position \a
|
---|
3543 | offset with the string \a arg.
|
---|
3544 | */
|
---|
3545 | void QDomCharacterData::replaceData( unsigned long offset, unsigned long count, const QString& arg )
|
---|
3546 | {
|
---|
3547 | if ( impl )
|
---|
3548 | IMPL->replaceData( offset, count, arg );
|
---|
3549 | }
|
---|
3550 |
|
---|
3551 | /*!
|
---|
3552 | Returns the type of node this object refers to (i.e. \c TextNode,
|
---|
3553 | \c CDATASectionNode, \c CommentNode or \c CharacterDataNode). For
|
---|
3554 | a \link isNull() null node\endlink \c CharacterDataNode is
|
---|
3555 | returned.
|
---|
3556 | */
|
---|
3557 | QDomNode::NodeType QDomCharacterData::nodeType() const
|
---|
3558 | {
|
---|
3559 | if( !impl )
|
---|
3560 | return CharacterDataNode;
|
---|
3561 | return QDomNode::nodeType();
|
---|
3562 | }
|
---|
3563 |
|
---|
3564 | /*!
|
---|
3565 | Returns TRUE.
|
---|
3566 | */
|
---|
3567 | bool QDomCharacterData::isCharacterData() const
|
---|
3568 | {
|
---|
3569 | return TRUE;
|
---|
3570 | }
|
---|
3571 |
|
---|
3572 | #undef IMPL
|
---|
3573 |
|
---|
3574 | /**************************************************************
|
---|
3575 | *
|
---|
3576 | * QDomAttrPrivate
|
---|
3577 | *
|
---|
3578 | **************************************************************/
|
---|
3579 |
|
---|
3580 | QDomAttrPrivate::QDomAttrPrivate( QDomDocumentPrivate* d, QDomNodePrivate* parent, const QString& name_ )
|
---|
3581 | : QDomNodePrivate( d, parent )
|
---|
3582 | {
|
---|
3583 | name = name_;
|
---|
3584 | m_specified = FALSE;
|
---|
3585 | }
|
---|
3586 |
|
---|
3587 | QDomAttrPrivate::QDomAttrPrivate( QDomDocumentPrivate* d, QDomNodePrivate* p, const QString& nsURI, const QString& qName )
|
---|
3588 | : QDomNodePrivate( d, p )
|
---|
3589 | {
|
---|
3590 | qt_split_namespace( prefix, name, qName, !nsURI.isNull() );
|
---|
3591 | namespaceURI = nsURI;
|
---|
3592 | createdWithDom1Interface = FALSE;
|
---|
3593 | m_specified = FALSE;
|
---|
3594 | }
|
---|
3595 |
|
---|
3596 | QDomAttrPrivate::QDomAttrPrivate( QDomAttrPrivate* n, bool deep )
|
---|
3597 | : QDomNodePrivate( n, deep )
|
---|
3598 | {
|
---|
3599 | m_specified = n->specified();
|
---|
3600 | }
|
---|
3601 |
|
---|
3602 | QDomAttrPrivate::~QDomAttrPrivate()
|
---|
3603 | {
|
---|
3604 | }
|
---|
3605 |
|
---|
3606 | void QDomAttrPrivate::setNodeValue( const QString& v )
|
---|
3607 | {
|
---|
3608 | value = v;
|
---|
3609 | QDomTextPrivate *t = new QDomTextPrivate( 0, this, v );
|
---|
3610 | // keep the refcount balanced: appendChild() does a ref() anyway.
|
---|
3611 | t->deref();
|
---|
3612 | if ( first ) {
|
---|
3613 | delete removeChild( first );
|
---|
3614 | }
|
---|
3615 | appendChild( t );
|
---|
3616 | }
|
---|
3617 |
|
---|
3618 | QDomNodePrivate* QDomAttrPrivate::cloneNode( bool deep )
|
---|
3619 | {
|
---|
3620 | QDomNodePrivate* p = new QDomAttrPrivate( this, deep );
|
---|
3621 | // We are not interested in this node
|
---|
3622 | p->deref();
|
---|
3623 | return p;
|
---|
3624 | }
|
---|
3625 |
|
---|
3626 | bool QDomAttrPrivate::specified() const
|
---|
3627 | {
|
---|
3628 | return m_specified;
|
---|
3629 | }
|
---|
3630 |
|
---|
3631 | /*
|
---|
3632 | Encode an attribute value upon saving.
|
---|
3633 | */
|
---|
3634 | static QString encodeAttr( const QString& str )
|
---|
3635 | {
|
---|
3636 | QString tmp( str );
|
---|
3637 | uint len = tmp.length();
|
---|
3638 | uint i = 0;
|
---|
3639 | while ( i < len ) {
|
---|
3640 | if ( tmp[(int)i] == '<' ) {
|
---|
3641 | tmp.replace( i, 1, "<" );
|
---|
3642 | len += 3;
|
---|
3643 | i += 4;
|
---|
3644 | } else if ( tmp[(int)i] == '"' ) {
|
---|
3645 | tmp.replace( i, 1, """ );
|
---|
3646 | len += 5;
|
---|
3647 | i += 6;
|
---|
3648 | } else if ( tmp[(int)i] == '&' ) {
|
---|
3649 | tmp.replace( i, 1, "&" );
|
---|
3650 | len += 4;
|
---|
3651 | i += 5;
|
---|
3652 | } else if ( tmp[(int)i] == '>' && i>=2 && tmp[(int)i-1]==']' && tmp[(int)i-2]==']' ) {
|
---|
3653 | tmp.replace( i, 1, ">" );
|
---|
3654 | len += 3;
|
---|
3655 | i += 4;
|
---|
3656 | } else {
|
---|
3657 | ++i;
|
---|
3658 | }
|
---|
3659 | }
|
---|
3660 |
|
---|
3661 | return tmp;
|
---|
3662 | }
|
---|
3663 |
|
---|
3664 | void QDomAttrPrivate::save( QTextStream& s, int, int ) const
|
---|
3665 | {
|
---|
3666 | if ( namespaceURI.isNull() ) {
|
---|
3667 | s << name << "=\"" << encodeAttr( value ) << "\"";
|
---|
3668 | } else {
|
---|
3669 | // ### optimize this (see comment of QDomElementPrivate::save()
|
---|
3670 | s << prefix << ":" << name << "=\"" << encodeAttr( value ) << "\""
|
---|
3671 | << " xmlns:" << prefix << "=\"" << encodeAttr( namespaceURI ) << "\"";
|
---|
3672 | }
|
---|
3673 | }
|
---|
3674 |
|
---|
3675 | /**************************************************************
|
---|
3676 | *
|
---|
3677 | * QDomAttr
|
---|
3678 | *
|
---|
3679 | **************************************************************/
|
---|
3680 |
|
---|
3681 | #define IMPL ((QDomAttrPrivate*)impl)
|
---|
3682 |
|
---|
3683 | /*!
|
---|
3684 | \class QDomAttr qdom.h
|
---|
3685 | \reentrant
|
---|
3686 | \brief The QDomAttr class represents one attribute of a QDomElement.
|
---|
3687 | \if defined(commercial)
|
---|
3688 | It is part of the <a href="commercialeditions.html">Qt Enterprise Edition</a>.
|
---|
3689 | \endif
|
---|
3690 |
|
---|
3691 | \module XML
|
---|
3692 | \ingroup xml-tools
|
---|
3693 |
|
---|
3694 | For example, the following piece of XML produces an element with
|
---|
3695 | no children, but two attributes:
|
---|
3696 |
|
---|
3697 | \code
|
---|
3698 | <link href="http://www.trolltech.com" color="red" />
|
---|
3699 | \endcode
|
---|
3700 |
|
---|
3701 | You can access the attributes of an element with code like this:
|
---|
3702 |
|
---|
3703 | \code
|
---|
3704 | QDomElement e = //...
|
---|
3705 | //...
|
---|
3706 | QDomAttr a = e.attributeNode( "href" );
|
---|
3707 | cout << a.value() << endl; // prints "http://www.trolltech.com"
|
---|
3708 | a.setValue( "http://doc.trolltech.com" ); // change the node's attribute
|
---|
3709 | QDomAttr a2 = e.attributeNode( "href" );
|
---|
3710 | cout << a2.value() << endl; // prints "http://doc.trolltech.com"
|
---|
3711 | \endcode
|
---|
3712 |
|
---|
3713 | This example also shows that changing an attribute received from
|
---|
3714 | an element changes the attribute of the element. If you do not
|
---|
3715 | want to change the value of the element's attribute you must
|
---|
3716 | use cloneNode() to get an independent copy of the attribute.
|
---|
3717 |
|
---|
3718 | QDomAttr can return the name() and value() of an attribute. An
|
---|
3719 | attribute's value is set with setValue(). If specified() returns
|
---|
3720 | TRUE the value was either set in the document or set with
|
---|
3721 | setValue(); otherwise the value hasn't been set. The node this
|
---|
3722 | attribute is attached to (if any) is returned by ownerElement().
|
---|
3723 |
|
---|
3724 | For further information about the Document Object Model see
|
---|
3725 | \link http://www.w3.org/TR/REC-DOM-Level-1/\endlink and
|
---|
3726 | \link http://www.w3.org/TR/DOM-Level-2-Core/\endlink.
|
---|
3727 | For a more general introduction of the DOM implementation see the
|
---|
3728 | QDomDocument documentation.
|
---|
3729 | */
|
---|
3730 |
|
---|
3731 |
|
---|
3732 | /*!
|
---|
3733 | Constructs an empty attribute.
|
---|
3734 | */
|
---|
3735 | QDomAttr::QDomAttr()
|
---|
3736 | {
|
---|
3737 | }
|
---|
3738 |
|
---|
3739 | /*!
|
---|
3740 | Constructs a copy of \a x.
|
---|
3741 |
|
---|
3742 | The data of the copy is shared (shallow copy): modifying one node
|
---|
3743 | will also change the other. If you want to make a deep copy, use
|
---|
3744 | cloneNode().
|
---|
3745 | */
|
---|
3746 | QDomAttr::QDomAttr( const QDomAttr& x )
|
---|
3747 | : QDomNode( x )
|
---|
3748 | {
|
---|
3749 | }
|
---|
3750 |
|
---|
3751 | QDomAttr::QDomAttr( QDomAttrPrivate* n )
|
---|
3752 | : QDomNode( n )
|
---|
3753 | {
|
---|
3754 | }
|
---|
3755 |
|
---|
3756 | /*!
|
---|
3757 | Assigns \a x to this DOM attribute.
|
---|
3758 |
|
---|
3759 | The data of the copy is shared (shallow copy): modifying one node
|
---|
3760 | will also change the other. If you want to make a deep copy, use
|
---|
3761 | cloneNode().
|
---|
3762 | */
|
---|
3763 | QDomAttr& QDomAttr::operator= ( const QDomAttr& x )
|
---|
3764 | {
|
---|
3765 | return (QDomAttr&) QDomNode::operator=( x );
|
---|
3766 | }
|
---|
3767 |
|
---|
3768 | /*!
|
---|
3769 | Destroys the object and frees its resources.
|
---|
3770 | */
|
---|
3771 | QDomAttr::~QDomAttr()
|
---|
3772 | {
|
---|
3773 | }
|
---|
3774 |
|
---|
3775 | /*!
|
---|
3776 | Returns the attribute's name.
|
---|
3777 | */
|
---|
3778 | QString QDomAttr::name() const
|
---|
3779 | {
|
---|
3780 | if ( !impl )
|
---|
3781 | return QString::null;
|
---|
3782 | return impl->nodeName();
|
---|
3783 | }
|
---|
3784 |
|
---|
3785 | /*!
|
---|
3786 | Returns TRUE if the attribute has either been expicitly specified
|
---|
3787 | in the XML document or was set by the user with setValue().
|
---|
3788 | Returns FALSE if the value hasn't been specified or set.
|
---|
3789 |
|
---|
3790 | \sa setValue()
|
---|
3791 | */
|
---|
3792 | bool QDomAttr::specified() const
|
---|
3793 | {
|
---|
3794 | if ( !impl )
|
---|
3795 | return FALSE;
|
---|
3796 | return IMPL->specified();
|
---|
3797 | }
|
---|
3798 |
|
---|
3799 | /*!
|
---|
3800 | Returns the element node this attribute is attached to or a \link
|
---|
3801 | QDomNode::isNull() null node\endlink if this attribute is not
|
---|
3802 | attached to any element.
|
---|
3803 | */
|
---|
3804 | QDomElement QDomAttr::ownerElement() const
|
---|
3805 | {
|
---|
3806 | if ( !impl && !impl->parent()->isElement() )
|
---|
3807 | return QDomElement();
|
---|
3808 | return QDomElement( (QDomElementPrivate*)(impl->parent()) );
|
---|
3809 | }
|
---|
3810 |
|
---|
3811 | /*!
|
---|
3812 | Returns the value of the attribute or QString::null if the
|
---|
3813 | attribute has not been specified.
|
---|
3814 |
|
---|
3815 | \sa specified() setValue()
|
---|
3816 | */
|
---|
3817 | QString QDomAttr::value() const
|
---|
3818 | {
|
---|
3819 | if ( !impl )
|
---|
3820 | return QString::null;
|
---|
3821 | return impl->nodeValue();
|
---|
3822 | }
|
---|
3823 |
|
---|
3824 | /*!
|
---|
3825 | Sets the attribute's value to \a v.
|
---|
3826 |
|
---|
3827 | \sa value()
|
---|
3828 | */
|
---|
3829 | void QDomAttr::setValue( const QString& v )
|
---|
3830 | {
|
---|
3831 | if ( !impl )
|
---|
3832 | return;
|
---|
3833 | impl->setNodeValue( v );
|
---|
3834 | IMPL->m_specified = TRUE;
|
---|
3835 | }
|
---|
3836 |
|
---|
3837 | /*!
|
---|
3838 | Returns \link QDomNode::NodeType AttributeNode\endlink.
|
---|
3839 | */
|
---|
3840 | QDomNode::NodeType QDomAttr::nodeType() const
|
---|
3841 | {
|
---|
3842 | return AttributeNode;
|
---|
3843 | }
|
---|
3844 |
|
---|
3845 | /*!
|
---|
3846 | Returns TRUE.
|
---|
3847 | */
|
---|
3848 | bool QDomAttr::isAttr() const
|
---|
3849 | {
|
---|
3850 | return TRUE;
|
---|
3851 | }
|
---|
3852 |
|
---|
3853 | #undef IMPL
|
---|
3854 |
|
---|
3855 | /**************************************************************
|
---|
3856 | *
|
---|
3857 | * QDomElementPrivate
|
---|
3858 | *
|
---|
3859 | **************************************************************/
|
---|
3860 |
|
---|
3861 | QDomElementPrivate::QDomElementPrivate( QDomDocumentPrivate* d, QDomNodePrivate* p,
|
---|
3862 | const QString& tagname )
|
---|
3863 | : QDomNodePrivate( d, p )
|
---|
3864 | {
|
---|
3865 | name = tagname;
|
---|
3866 | m_attr = new QDomNamedNodeMapPrivate( this );
|
---|
3867 | }
|
---|
3868 |
|
---|
3869 | QDomElementPrivate::QDomElementPrivate( QDomDocumentPrivate* d, QDomNodePrivate* p,
|
---|
3870 | const QString& nsURI, const QString& qName )
|
---|
3871 | : QDomNodePrivate( d, p )
|
---|
3872 | {
|
---|
3873 | qt_split_namespace( prefix, name, qName, !nsURI.isNull() );
|
---|
3874 | namespaceURI = nsURI;
|
---|
3875 | createdWithDom1Interface = FALSE;
|
---|
3876 | m_attr = new QDomNamedNodeMapPrivate( this );
|
---|
3877 | }
|
---|
3878 |
|
---|
3879 | QDomElementPrivate::QDomElementPrivate( QDomElementPrivate* n, bool deep ) :
|
---|
3880 | QDomNodePrivate( n, deep )
|
---|
3881 | {
|
---|
3882 | m_attr = n->m_attr->clone( this );
|
---|
3883 | // Reference is down to 0, so we set it to 1 here.
|
---|
3884 | m_attr->ref();
|
---|
3885 | }
|
---|
3886 |
|
---|
3887 | QDomElementPrivate::~QDomElementPrivate()
|
---|
3888 | {
|
---|
3889 | if ( m_attr->deref() )
|
---|
3890 | delete m_attr;
|
---|
3891 | }
|
---|
3892 |
|
---|
3893 | QDomNodePrivate* QDomElementPrivate::cloneNode( bool deep)
|
---|
3894 | {
|
---|
3895 | QDomNodePrivate* p = new QDomElementPrivate( this, deep );
|
---|
3896 | // We are not interested in this node
|
---|
3897 | p->deref();
|
---|
3898 | return p;
|
---|
3899 | }
|
---|
3900 |
|
---|
3901 | QString QDomElementPrivate::attribute( const QString& name_, const QString& defValue ) const
|
---|
3902 | {
|
---|
3903 | QDomNodePrivate* n = m_attr->namedItem( name_ );
|
---|
3904 | if ( !n )
|
---|
3905 | return defValue;
|
---|
3906 |
|
---|
3907 | return n->nodeValue();
|
---|
3908 | }
|
---|
3909 |
|
---|
3910 | QString QDomElementPrivate::attributeNS( const QString& nsURI, const QString& localName, const QString& defValue ) const
|
---|
3911 | {
|
---|
3912 | QDomNodePrivate* n = m_attr->namedItemNS( nsURI, localName );
|
---|
3913 | if ( !n )
|
---|
3914 | return defValue;
|
---|
3915 |
|
---|
3916 | return n->nodeValue();
|
---|
3917 | }
|
---|
3918 |
|
---|
3919 | void QDomElementPrivate::setAttribute( const QString& aname, const QString& newValue )
|
---|
3920 | {
|
---|
3921 | QDomNodePrivate* n = m_attr->namedItem( aname );
|
---|
3922 | if ( !n ) {
|
---|
3923 | n = new QDomAttrPrivate( ownerDocument(), this, aname );
|
---|
3924 | n->setNodeValue( newValue );
|
---|
3925 |
|
---|
3926 | // Referencing is done by the map, so we set the reference counter back
|
---|
3927 | // to 0 here. This is ok since we created the QDomAttrPrivate.
|
---|
3928 | n->deref();
|
---|
3929 | m_attr->setNamedItem( n );
|
---|
3930 | } else {
|
---|
3931 | n->setNodeValue( newValue );
|
---|
3932 | }
|
---|
3933 | }
|
---|
3934 |
|
---|
3935 | void QDomElementPrivate::setAttributeNS( const QString& nsURI, const QString& qName, const QString& newValue )
|
---|
3936 | {
|
---|
3937 | QString prefix, localName;
|
---|
3938 | qt_split_namespace( prefix, localName, qName, TRUE );
|
---|
3939 | QDomNodePrivate* n = m_attr->namedItemNS( nsURI, localName );
|
---|
3940 | if ( !n ) {
|
---|
3941 | n = new QDomAttrPrivate( ownerDocument(), this, nsURI, qName );
|
---|
3942 | n->setNodeValue( newValue );
|
---|
3943 |
|
---|
3944 | // Referencing is done by the map, so we set the reference counter back
|
---|
3945 | // to 0 here. This is ok since we created the QDomAttrPrivate.
|
---|
3946 | n->deref();
|
---|
3947 | m_attr->setNamedItem( n );
|
---|
3948 | } else {
|
---|
3949 | n->setNodeValue( newValue );
|
---|
3950 | n->prefix = prefix;
|
---|
3951 | }
|
---|
3952 | }
|
---|
3953 |
|
---|
3954 | void QDomElementPrivate::removeAttribute( const QString& aname )
|
---|
3955 | {
|
---|
3956 | QDomNodePrivate* p = m_attr->removeNamedItem( aname );
|
---|
3957 | if ( p && p->count == 0 )
|
---|
3958 | delete p;
|
---|
3959 | }
|
---|
3960 |
|
---|
3961 | QDomAttrPrivate* QDomElementPrivate::attributeNode( const QString& aname )
|
---|
3962 | {
|
---|
3963 | return (QDomAttrPrivate*)m_attr->namedItem( aname );
|
---|
3964 | }
|
---|
3965 |
|
---|
3966 | QDomAttrPrivate* QDomElementPrivate::attributeNodeNS( const QString& nsURI, const QString& localName )
|
---|
3967 | {
|
---|
3968 | return (QDomAttrPrivate*)m_attr->namedItemNS( nsURI, localName );
|
---|
3969 | }
|
---|
3970 |
|
---|
3971 | QDomAttrPrivate* QDomElementPrivate::setAttributeNode( QDomAttrPrivate* newAttr )
|
---|
3972 | {
|
---|
3973 | QDomNodePrivate* n = m_attr->namedItem( newAttr->nodeName() );
|
---|
3974 |
|
---|
3975 | // Referencing is done by the maps
|
---|
3976 | m_attr->setNamedItem( newAttr );
|
---|
3977 |
|
---|
3978 | return (QDomAttrPrivate*)n;
|
---|
3979 | }
|
---|
3980 |
|
---|
3981 | QDomAttrPrivate* QDomElementPrivate::setAttributeNodeNS( QDomAttrPrivate* newAttr )
|
---|
3982 | {
|
---|
3983 | QDomNodePrivate* n = 0;
|
---|
3984 | if ( !newAttr->prefix.isNull() )
|
---|
3985 | n = m_attr->namedItemNS( newAttr->namespaceURI, newAttr->name );
|
---|
3986 |
|
---|
3987 | // Referencing is done by the maps
|
---|
3988 | m_attr->setNamedItem( newAttr );
|
---|
3989 |
|
---|
3990 | return (QDomAttrPrivate*)n;
|
---|
3991 | }
|
---|
3992 |
|
---|
3993 | QDomAttrPrivate* QDomElementPrivate::removeAttributeNode( QDomAttrPrivate* oldAttr )
|
---|
3994 | {
|
---|
3995 | return (QDomAttrPrivate*)m_attr->removeNamedItem( oldAttr->nodeName() );
|
---|
3996 | }
|
---|
3997 |
|
---|
3998 | bool QDomElementPrivate::hasAttribute( const QString& aname )
|
---|
3999 | {
|
---|
4000 | return m_attr->contains( aname );
|
---|
4001 | }
|
---|
4002 |
|
---|
4003 | bool QDomElementPrivate::hasAttributeNS( const QString& nsURI, const QString& localName )
|
---|
4004 | {
|
---|
4005 | return m_attr->containsNS( nsURI, localName );
|
---|
4006 | }
|
---|
4007 |
|
---|
4008 | QString QDomElementPrivate::text()
|
---|
4009 | {
|
---|
4010 | QString t( "" );
|
---|
4011 |
|
---|
4012 | QDomNodePrivate* p = first;
|
---|
4013 | while ( p ) {
|
---|
4014 | if ( p->isText() || p->isCDATASection() )
|
---|
4015 | t += p->nodeValue();
|
---|
4016 | else if ( p->isElement() )
|
---|
4017 | t += ((QDomElementPrivate*)p)->text();
|
---|
4018 | p = p->next;
|
---|
4019 | }
|
---|
4020 |
|
---|
4021 | return t;
|
---|
4022 | }
|
---|
4023 |
|
---|
4024 | void QDomElementPrivate::save( QTextStream& s, int depth, int indent ) const
|
---|
4025 | {
|
---|
4026 | if ( !( prev && prev->isText() ) )
|
---|
4027 | for ( int i = 0; i < depth*indent; ++i )
|
---|
4028 | s << " ";
|
---|
4029 |
|
---|
4030 | QString qName( name );
|
---|
4031 | QString nsDecl( "" );
|
---|
4032 | if ( !namespaceURI.isNull() ) {
|
---|
4033 | // ### optimize this, so that you only declare namespaces that are not
|
---|
4034 | // yet declared -- we loose default namespace mappings, so maybe we
|
---|
4035 | // should rather store the information that we get from
|
---|
4036 | // startPrefixMapping()/endPrefixMapping() and use them (you have to
|
---|
4037 | // take care if the DOM tree is modified, though)
|
---|
4038 | if ( prefix.isEmpty() ) {
|
---|
4039 | nsDecl = " xmlns";
|
---|
4040 | } else {
|
---|
4041 | qName = prefix + ":" + name;
|
---|
4042 | nsDecl = " xmlns:" + prefix;
|
---|
4043 | }
|
---|
4044 | nsDecl += "=\"" + encodeAttr( namespaceURI ) + "\"";
|
---|
4045 | }
|
---|
4046 | s << "<" << qName << nsDecl;
|
---|
4047 |
|
---|
4048 | if ( !m_attr->map.isEmpty() ) {
|
---|
4049 | s << " ";
|
---|
4050 | QDictIterator<QDomNodePrivate> it( m_attr->map );
|
---|
4051 | for ( ; it.current(); ++it ) {
|
---|
4052 | it.current()->save( s, 0, indent );
|
---|
4053 | s << " ";
|
---|
4054 | }
|
---|
4055 | }
|
---|
4056 |
|
---|
4057 | if ( last ) {
|
---|
4058 | // has child nodes
|
---|
4059 | if ( first->isText() )
|
---|
4060 | s << ">";
|
---|
4061 | else
|
---|
4062 | s << ">" << endl;
|
---|
4063 | QDomNodePrivate::save( s, depth + 1, indent);
|
---|
4064 | if ( !last->isText() )
|
---|
4065 | for( int i = 0; i < depth*indent; ++i )
|
---|
4066 | s << " ";
|
---|
4067 |
|
---|
4068 | s << "</" << qName << ">";
|
---|
4069 | } else {
|
---|
4070 | s << "/>";
|
---|
4071 | }
|
---|
4072 | if ( !( next && next->isText() ) )
|
---|
4073 | s << endl;
|
---|
4074 | }
|
---|
4075 |
|
---|
4076 | /**************************************************************
|
---|
4077 | *
|
---|
4078 | * QDomElement
|
---|
4079 | *
|
---|
4080 | **************************************************************/
|
---|
4081 |
|
---|
4082 | #define IMPL ((QDomElementPrivate*)impl)
|
---|
4083 |
|
---|
4084 | /*!
|
---|
4085 | \class QDomElement qdom.h
|
---|
4086 | \reentrant
|
---|
4087 | \brief The QDomElement class represents one element in the DOM tree.
|
---|
4088 | \if defined(commercial)
|
---|
4089 | It is part of the <a href="commercialeditions.html">Qt Enterprise Edition</a>.
|
---|
4090 | \endif
|
---|
4091 |
|
---|
4092 | \module XML
|
---|
4093 | \ingroup xml-tools
|
---|
4094 |
|
---|
4095 | Elements have a tagName() and zero or more attributes associated
|
---|
4096 | with them. The tag name can be changed with setTagName().
|
---|
4097 |
|
---|
4098 | Element attributes are represented by QDomAttr objects that can
|
---|
4099 | be queried using the attribute() and attributeNode() functions.
|
---|
4100 | You can set attributes with the setAttribute() and
|
---|
4101 | setAttributeNode() functions. Attributes can be removed with
|
---|
4102 | removeAttribute(). There are namespace-aware equivalents to these
|
---|
4103 | functions, i.e. setAttributeNS(), setAttributeNodeNS() and
|
---|
4104 | removeAttributeNS().
|
---|
4105 |
|
---|
4106 | If you want to access the text of a node use text(), e.g.
|
---|
4107 | \code
|
---|
4108 | QDomElement e = //...
|
---|
4109 | //...
|
---|
4110 | QString s = e.text()
|
---|
4111 | \endcode
|
---|
4112 | The text() function operates recursively to find the text (since
|
---|
4113 | not all elements contain text). If you want to find all the text
|
---|
4114 | in all of a node's children, iterate over the children looking for
|
---|
4115 | QDomText nodes, e.g.
|
---|
4116 | \code
|
---|
4117 | QString text;
|
---|
4118 | QDomElement element = doc.documentElement();
|
---|
4119 | for( QDomNode n = element.firstChild(); !n.isNull(); n = n.nextSibling() )
|
---|
4120 | {
|
---|
4121 | QDomText t = n.toText();
|
---|
4122 | if ( !t.isNull() )
|
---|
4123 | text += t.data();
|
---|
4124 | }
|
---|
4125 | \endcode
|
---|
4126 | Note that we attempt to convert each node to a text node and use
|
---|
4127 | text() rather than using firstChild().toText().data() or
|
---|
4128 | n.toText().data() directly on the node, because the node may not
|
---|
4129 | be a text element.
|
---|
4130 |
|
---|
4131 | You can get a list of all the decendents of an element which have
|
---|
4132 | a specified tag name with elementsByTagName() or
|
---|
4133 | elementsByTagNameNS().
|
---|
4134 |
|
---|
4135 | For further information about the Document Object Model see
|
---|
4136 | \link http://www.w3.org/TR/REC-DOM-Level-1/\endlink and
|
---|
4137 | \link http://www.w3.org/TR/DOM-Level-2-Core/\endlink.
|
---|
4138 | For a more general introduction of the DOM implementation see the
|
---|
4139 | QDomDocument documentation.
|
---|
4140 | */
|
---|
4141 |
|
---|
4142 | /*!
|
---|
4143 | Constructs an empty element. Use the QDomDocument::createElement()
|
---|
4144 | function to construct elements with content.
|
---|
4145 | */
|
---|
4146 | QDomElement::QDomElement()
|
---|
4147 | : QDomNode()
|
---|
4148 | {
|
---|
4149 | }
|
---|
4150 |
|
---|
4151 | /*!
|
---|
4152 | Constructs a copy of \a x.
|
---|
4153 |
|
---|
4154 | The data of the copy is shared (shallow copy): modifying one node
|
---|
4155 | will also change the other. If you want to make a deep copy, use
|
---|
4156 | cloneNode().
|
---|
4157 | */
|
---|
4158 | QDomElement::QDomElement( const QDomElement& x )
|
---|
4159 | : QDomNode( x )
|
---|
4160 | {
|
---|
4161 | }
|
---|
4162 |
|
---|
4163 | QDomElement::QDomElement( QDomElementPrivate* n )
|
---|
4164 | : QDomNode( n )
|
---|
4165 | {
|
---|
4166 | }
|
---|
4167 |
|
---|
4168 | /*!
|
---|
4169 | Assigns \a x to this DOM element.
|
---|
4170 |
|
---|
4171 | The data of the copy is shared (shallow copy): modifying one node
|
---|
4172 | will also change the other. If you want to make a deep copy, use
|
---|
4173 | cloneNode().
|
---|
4174 | */
|
---|
4175 | QDomElement& QDomElement::operator= ( const QDomElement& x )
|
---|
4176 | {
|
---|
4177 | return (QDomElement&) QDomNode::operator=( x );
|
---|
4178 | }
|
---|
4179 |
|
---|
4180 | /*!
|
---|
4181 | Destroys the object and frees its resources.
|
---|
4182 | */
|
---|
4183 | QDomElement::~QDomElement()
|
---|
4184 | {
|
---|
4185 | }
|
---|
4186 |
|
---|
4187 | /*!
|
---|
4188 | Returns \c ElementNode.
|
---|
4189 | */
|
---|
4190 | QDomNode::NodeType QDomElement::nodeType() const
|
---|
4191 | {
|
---|
4192 | return ElementNode;
|
---|
4193 | }
|
---|
4194 |
|
---|
4195 | /*!
|
---|
4196 | Sets this element's tag name to \a name.
|
---|
4197 |
|
---|
4198 | \sa tagName()
|
---|
4199 | */
|
---|
4200 | void QDomElement::setTagName( const QString& name )
|
---|
4201 | {
|
---|
4202 | if ( impl )
|
---|
4203 | impl->name = name;
|
---|
4204 | }
|
---|
4205 |
|
---|
4206 | /*!
|
---|
4207 | Returns the tag name of this element. For an XML element like this:
|
---|
4208 | \code
|
---|
4209 | <img src="myimg.png">
|
---|
4210 | \endcode
|
---|
4211 | the tagname would return "img".
|
---|
4212 |
|
---|
4213 | \sa setTagName()
|
---|
4214 | */
|
---|
4215 | QString QDomElement::tagName() const
|
---|
4216 | {
|
---|
4217 | if ( !impl )
|
---|
4218 | return QString::null;
|
---|
4219 | return impl->nodeName();
|
---|
4220 | }
|
---|
4221 |
|
---|
4222 | /*!
|
---|
4223 | Returns the attribute called \a name. If the attribute does not
|
---|
4224 | exist \a defValue is returned.
|
---|
4225 |
|
---|
4226 | \sa setAttribute() attributeNode() setAttributeNode() attributeNS()
|
---|
4227 | */
|
---|
4228 | QString QDomElement::attribute( const QString& name, const QString& defValue ) const
|
---|
4229 | {
|
---|
4230 | if ( !impl )
|
---|
4231 | return defValue;
|
---|
4232 | return IMPL->attribute( name, defValue );
|
---|
4233 | }
|
---|
4234 |
|
---|
4235 | /*!
|
---|
4236 | Adds an attribute called \a name with value \a value. If an
|
---|
4237 | attribute with the same name exists, its value is replaced by \a
|
---|
4238 | value.
|
---|
4239 |
|
---|
4240 | \sa attribute() setAttributeNode() setAttributeNS()
|
---|
4241 | */
|
---|
4242 | void QDomElement::setAttribute( const QString& name, const QString& value )
|
---|
4243 | {
|
---|
4244 | if ( !impl )
|
---|
4245 | return;
|
---|
4246 | IMPL->setAttribute( name, value );
|
---|
4247 | }
|
---|
4248 |
|
---|
4249 | /*!
|
---|
4250 | \overload
|
---|
4251 | */
|
---|
4252 | void QDomElement::setAttribute( const QString& name, int value )
|
---|
4253 | {
|
---|
4254 | // ### 4.0: inline
|
---|
4255 | setAttribute( name, long(value) );
|
---|
4256 | }
|
---|
4257 |
|
---|
4258 | /*!
|
---|
4259 | \overload
|
---|
4260 | */
|
---|
4261 | void QDomElement::setAttribute( const QString& name, uint value )
|
---|
4262 | {
|
---|
4263 | // ### 4.0: inline
|
---|
4264 | setAttribute( name, ulong(value) );
|
---|
4265 | }
|
---|
4266 |
|
---|
4267 | /*!
|
---|
4268 | \overload
|
---|
4269 | */
|
---|
4270 | void QDomElement::setAttribute( const QString& name, long value )
|
---|
4271 | {
|
---|
4272 | if ( !impl )
|
---|
4273 | return;
|
---|
4274 | QString x;
|
---|
4275 | x.setNum( value );
|
---|
4276 | IMPL->setAttribute( name, x );
|
---|
4277 | }
|
---|
4278 |
|
---|
4279 | /*!
|
---|
4280 | \overload
|
---|
4281 | */
|
---|
4282 | void QDomElement::setAttribute( const QString& name, ulong value )
|
---|
4283 | {
|
---|
4284 | if ( !impl )
|
---|
4285 | return;
|
---|
4286 | QString x;
|
---|
4287 | x.setNum( value );
|
---|
4288 | IMPL->setAttribute( name, x );
|
---|
4289 | }
|
---|
4290 |
|
---|
4291 | /*!
|
---|
4292 | \overload
|
---|
4293 | */
|
---|
4294 | void QDomElement::setAttribute( const QString& name, double value )
|
---|
4295 | {
|
---|
4296 | if ( !impl )
|
---|
4297 | return;
|
---|
4298 | QString x;
|
---|
4299 | x.setNum( value );
|
---|
4300 | IMPL->setAttribute( name, x );
|
---|
4301 | }
|
---|
4302 |
|
---|
4303 | /*!
|
---|
4304 | Removes the attribute called name \a name from this element.
|
---|
4305 |
|
---|
4306 | \sa setAttribute() attribute() removeAttributeNS()
|
---|
4307 | */
|
---|
4308 | void QDomElement::removeAttribute( const QString& name )
|
---|
4309 | {
|
---|
4310 | if ( !impl )
|
---|
4311 | return;
|
---|
4312 | IMPL->removeAttribute( name );
|
---|
4313 | }
|
---|
4314 |
|
---|
4315 | /*!
|
---|
4316 | Returns the QDomAttr object that corresponds to the attribute
|
---|
4317 | called \a name. If no such attribute exists a \link
|
---|
4318 | QDomNode::isNull() null attribute\endlink is returned.
|
---|
4319 |
|
---|
4320 | \sa setAttributeNode() attribute() setAttribute() attributeNodeNS()
|
---|
4321 | */
|
---|
4322 | QDomAttr QDomElement::attributeNode( const QString& name)
|
---|
4323 | {
|
---|
4324 | if ( !impl )
|
---|
4325 | return QDomAttr();
|
---|
4326 | return QDomAttr( IMPL->attributeNode( name ) );
|
---|
4327 | }
|
---|
4328 |
|
---|
4329 | /*!
|
---|
4330 | Adds the attribute \a newAttr to this element.
|
---|
4331 |
|
---|
4332 | If the element has another attribute that has the same name as \a
|
---|
4333 | newAttr, this function replaces that attribute and returns it;
|
---|
4334 | otherwise the function returns a \link QDomNode::isNull() null
|
---|
4335 | attribute\endlink.
|
---|
4336 |
|
---|
4337 | \sa attributeNode() setAttribute() setAttributeNodeNS()
|
---|
4338 | */
|
---|
4339 | QDomAttr QDomElement::setAttributeNode( const QDomAttr& newAttr )
|
---|
4340 | {
|
---|
4341 | if ( !impl )
|
---|
4342 | return QDomAttr();
|
---|
4343 | return QDomAttr( IMPL->setAttributeNode( ((QDomAttrPrivate*)newAttr.impl) ) );
|
---|
4344 | }
|
---|
4345 |
|
---|
4346 | /*!
|
---|
4347 | Removes the attribute \a oldAttr from the element and returns it.
|
---|
4348 |
|
---|
4349 | \sa attributeNode() setAttributeNode()
|
---|
4350 | */
|
---|
4351 | QDomAttr QDomElement::removeAttributeNode( const QDomAttr& oldAttr )
|
---|
4352 | {
|
---|
4353 | if ( !impl )
|
---|
4354 | return QDomAttr(); // ### should this return oldAttr?
|
---|
4355 | return QDomAttr( IMPL->removeAttributeNode( ((QDomAttrPrivate*)oldAttr.impl) ) );
|
---|
4356 | }
|
---|
4357 |
|
---|
4358 | /*!
|
---|
4359 | Returns a QDomNodeList containing all descendent elements of this
|
---|
4360 | element that are called \a tagname. The order they are in the node
|
---|
4361 | list is the order they are encountered in a preorder traversal of
|
---|
4362 | the element tree.
|
---|
4363 |
|
---|
4364 | \sa elementsByTagNameNS() QDomDocument::elementsByTagName()
|
---|
4365 | */
|
---|
4366 | QDomNodeList QDomElement::elementsByTagName( const QString& tagname ) const
|
---|
4367 | {
|
---|
4368 | return QDomNodeList( new QDomNodeListPrivate( impl, tagname ) );
|
---|
4369 | }
|
---|
4370 |
|
---|
4371 | /*!
|
---|
4372 | Returns TRUE.
|
---|
4373 | */
|
---|
4374 | bool QDomElement::isElement() const
|
---|
4375 | {
|
---|
4376 | return TRUE;
|
---|
4377 | }
|
---|
4378 |
|
---|
4379 | /*!
|
---|
4380 | Returns a QDomNamedNodeMap containing all this element's attributes.
|
---|
4381 |
|
---|
4382 | \sa attribute() setAttribute() attributeNode() setAttributeNode()
|
---|
4383 | */
|
---|
4384 | QDomNamedNodeMap QDomElement::attributes() const
|
---|
4385 | {
|
---|
4386 | if ( !impl )
|
---|
4387 | return QDomNamedNodeMap();
|
---|
4388 | return QDomNamedNodeMap( IMPL->attributes() );
|
---|
4389 | }
|
---|
4390 |
|
---|
4391 | /*!
|
---|
4392 | Returns TRUE if this element has an attribute called \a name;
|
---|
4393 | otherwise returns FALSE.
|
---|
4394 | */
|
---|
4395 | bool QDomElement::hasAttribute( const QString& name ) const
|
---|
4396 | {
|
---|
4397 | if ( !impl )
|
---|
4398 | return FALSE;
|
---|
4399 | return IMPL->hasAttribute( name );
|
---|
4400 | }
|
---|
4401 |
|
---|
4402 | /*!
|
---|
4403 | Returns the attribute with the local name \a localName and the
|
---|
4404 | namespace URI \a nsURI. If the attribute does not exist \a
|
---|
4405 | defValue is returned.
|
---|
4406 |
|
---|
4407 | \sa setAttributeNS() attributeNodeNS() setAttributeNodeNS() attribute()
|
---|
4408 | */
|
---|
4409 | QString QDomElement::attributeNS( const QString nsURI, const QString& localName, const QString& defValue ) const
|
---|
4410 | {
|
---|
4411 | if ( !impl )
|
---|
4412 | return defValue;
|
---|
4413 | return IMPL->attributeNS( nsURI, localName, defValue );
|
---|
4414 | }
|
---|
4415 |
|
---|
4416 | /*!
|
---|
4417 | Adds an attribute with the qualified name \a qName and the
|
---|
4418 | namespace URI \a nsURI with the value \a value. If an attribute
|
---|
4419 | with the same local name and namespace URI exists, its prefix is
|
---|
4420 | replaced by the prefix of \a qName and its value is repaced by \a
|
---|
4421 | value.
|
---|
4422 |
|
---|
4423 | Although \a qName is the qualified name, the local name is used to
|
---|
4424 | decide if an existing attribute's value should be replaced.
|
---|
4425 |
|
---|
4426 | \sa attributeNS() setAttributeNodeNS() setAttribute()
|
---|
4427 | */
|
---|
4428 | void QDomElement::setAttributeNS( const QString nsURI, const QString& qName, const QString& value )
|
---|
4429 | {
|
---|
4430 | if ( !impl )
|
---|
4431 | return;
|
---|
4432 | IMPL->setAttributeNS( nsURI, qName, value );
|
---|
4433 | }
|
---|
4434 |
|
---|
4435 | /*!
|
---|
4436 | \overload
|
---|
4437 | */
|
---|
4438 | void QDomElement::setAttributeNS( const QString nsURI, const QString& qName, int value )
|
---|
4439 | {
|
---|
4440 | // ### 4.0: inline
|
---|
4441 | setAttributeNS( nsURI, qName, long(value) );
|
---|
4442 | }
|
---|
4443 |
|
---|
4444 | /*!
|
---|
4445 | \overload
|
---|
4446 | */
|
---|
4447 | void QDomElement::setAttributeNS( const QString nsURI, const QString& qName, uint value )
|
---|
4448 | {
|
---|
4449 | // ### 4.0: inline
|
---|
4450 | setAttributeNS( nsURI, qName, ulong(value) );
|
---|
4451 | }
|
---|
4452 |
|
---|
4453 | /*!
|
---|
4454 | \overload
|
---|
4455 | */
|
---|
4456 | void QDomElement::setAttributeNS( const QString nsURI, const QString& qName, long value )
|
---|
4457 | {
|
---|
4458 | if ( !impl )
|
---|
4459 | return;
|
---|
4460 | QString x;
|
---|
4461 | x.setNum( value );
|
---|
4462 | IMPL->setAttributeNS( nsURI, qName, x );
|
---|
4463 | }
|
---|
4464 |
|
---|
4465 | /*!
|
---|
4466 | \overload
|
---|
4467 | */
|
---|
4468 | void QDomElement::setAttributeNS( const QString nsURI, const QString& qName, ulong value )
|
---|
4469 | {
|
---|
4470 | if ( !impl )
|
---|
4471 | return;
|
---|
4472 | QString x;
|
---|
4473 | x.setNum( value );
|
---|
4474 | IMPL->setAttributeNS( nsURI, qName, x );
|
---|
4475 | }
|
---|
4476 |
|
---|
4477 | /*!
|
---|
4478 | \overload
|
---|
4479 | */
|
---|
4480 | void QDomElement::setAttributeNS( const QString nsURI, const QString& qName, double value )
|
---|
4481 | {
|
---|
4482 | if ( !impl )
|
---|
4483 | return;
|
---|
4484 | QString x;
|
---|
4485 | x.setNum( value );
|
---|
4486 | IMPL->setAttributeNS( nsURI, qName, x );
|
---|
4487 | }
|
---|
4488 |
|
---|
4489 | /*!
|
---|
4490 | Removes the attribute with the local name \a localName and the
|
---|
4491 | namespace URI \a nsURI from this element.
|
---|
4492 |
|
---|
4493 | \sa setAttributeNS() attributeNS() removeAttribute()
|
---|
4494 | */
|
---|
4495 | void QDomElement::removeAttributeNS( const QString& nsURI, const QString& localName )
|
---|
4496 | {
|
---|
4497 | if ( !impl )
|
---|
4498 | return;
|
---|
4499 | QDomNodePrivate *n = IMPL->attributeNodeNS( nsURI, localName );
|
---|
4500 | if ( !n )
|
---|
4501 | return;
|
---|
4502 | IMPL->removeAttribute( n->nodeName() );
|
---|
4503 | }
|
---|
4504 |
|
---|
4505 | /*!
|
---|
4506 | Returns the QDomAttr object that corresponds to the attribute with
|
---|
4507 | the local name \a localName and the namespace URI \a nsURI. If no
|
---|
4508 | such attribute exists a \link QDomNode::isNull() null
|
---|
4509 | attribute\endlink is returned.
|
---|
4510 |
|
---|
4511 | \sa setAttributeNode() attribute() setAttribute() attributeNodeNS()
|
---|
4512 | */
|
---|
4513 | QDomAttr QDomElement::attributeNodeNS( const QString& nsURI, const QString& localName )
|
---|
4514 | {
|
---|
4515 | if ( !impl )
|
---|
4516 | return QDomAttr();
|
---|
4517 | return QDomAttr( IMPL->attributeNodeNS( nsURI, localName ) );
|
---|
4518 | }
|
---|
4519 |
|
---|
4520 | /*!
|
---|
4521 | Adds the attribute \a newAttr to this element.
|
---|
4522 |
|
---|
4523 | If the element has another attribute that has the same local name
|
---|
4524 | and namespace URI as \a newAttr, this function replaces that
|
---|
4525 | attribute and returns it; otherwise the function returns a \link
|
---|
4526 | QDomNode::isNull() null attribute\endlink.
|
---|
4527 |
|
---|
4528 | \sa attributeNodeNS() setAttributeNS() setAttributeNode()
|
---|
4529 | */
|
---|
4530 | QDomAttr QDomElement::setAttributeNodeNS( const QDomAttr& newAttr )
|
---|
4531 | {
|
---|
4532 | if ( !impl )
|
---|
4533 | return QDomAttr();
|
---|
4534 | return QDomAttr( IMPL->setAttributeNodeNS( ((QDomAttrPrivate*)newAttr.impl) ) );
|
---|
4535 | }
|
---|
4536 |
|
---|
4537 | /*!
|
---|
4538 | Returns a QDomNodeList containing all the descendent elements of
|
---|
4539 | this element with the local name \a localName and the namespace
|
---|
4540 | URI \a nsURI. The order they are in the node list is the order
|
---|
4541 | they are encountered in a preorder traversal of the element tree.
|
---|
4542 |
|
---|
4543 | \sa elementsByTagName() QDomDocument::elementsByTagNameNS()
|
---|
4544 | */
|
---|
4545 | QDomNodeList QDomElement::elementsByTagNameNS( const QString& nsURI, const QString& localName ) const
|
---|
4546 | {
|
---|
4547 | return QDomNodeList( new QDomNodeListPrivate( impl, nsURI, localName ) );
|
---|
4548 | }
|
---|
4549 |
|
---|
4550 | /*!
|
---|
4551 | Returns TRUE if this element has an attribute with the local name
|
---|
4552 | \a localName and the namespace URI \a nsURI; otherwise returns
|
---|
4553 | FALSE.
|
---|
4554 | */
|
---|
4555 | bool QDomElement::hasAttributeNS( const QString& nsURI, const QString& localName ) const
|
---|
4556 | {
|
---|
4557 | if ( !impl )
|
---|
4558 | return FALSE;
|
---|
4559 | return IMPL->hasAttributeNS( nsURI, localName );
|
---|
4560 | }
|
---|
4561 |
|
---|
4562 | /*!
|
---|
4563 | Returns the element's text or QString::null.
|
---|
4564 |
|
---|
4565 | Example:
|
---|
4566 | \code
|
---|
4567 | <h1>Hello <b>Qt</b> <![CDATA[<xml is cool>]]></h1>
|
---|
4568 | \endcode
|
---|
4569 |
|
---|
4570 | The function text() of the QDomElement for the <h1> tag,
|
---|
4571 | will return "Hello Qt <xml is cool>".
|
---|
4572 |
|
---|
4573 | Comments are ignored by this function. It only evaluates QDomText
|
---|
4574 | and QDomCDATASection objects.
|
---|
4575 | */
|
---|
4576 | QString QDomElement::text() const
|
---|
4577 | {
|
---|
4578 | if ( !impl )
|
---|
4579 | return QString::null;
|
---|
4580 | return IMPL->text();
|
---|
4581 | }
|
---|
4582 |
|
---|
4583 | #undef IMPL
|
---|
4584 |
|
---|
4585 | /**************************************************************
|
---|
4586 | *
|
---|
4587 | * QDomTextPrivate
|
---|
4588 | *
|
---|
4589 | **************************************************************/
|
---|
4590 |
|
---|
4591 | QDomTextPrivate::QDomTextPrivate( QDomDocumentPrivate* d, QDomNodePrivate* parent, const QString& value )
|
---|
4592 | : QDomCharacterDataPrivate( d, parent, value )
|
---|
4593 | {
|
---|
4594 | name = "#text";
|
---|
4595 | }
|
---|
4596 |
|
---|
4597 | QDomTextPrivate::QDomTextPrivate( QDomTextPrivate* n, bool deep )
|
---|
4598 | : QDomCharacterDataPrivate( n, deep )
|
---|
4599 | {
|
---|
4600 | }
|
---|
4601 |
|
---|
4602 | QDomTextPrivate::~QDomTextPrivate()
|
---|
4603 | {
|
---|
4604 | }
|
---|
4605 |
|
---|
4606 | QDomNodePrivate* QDomTextPrivate::cloneNode( bool deep)
|
---|
4607 | {
|
---|
4608 | QDomNodePrivate* p = new QDomTextPrivate( this, deep );
|
---|
4609 | // We are not interested in this node
|
---|
4610 | p->deref();
|
---|
4611 | return p;
|
---|
4612 | }
|
---|
4613 |
|
---|
4614 | QDomTextPrivate* QDomTextPrivate::splitText( int offset )
|
---|
4615 | {
|
---|
4616 | if ( !parent() ) {
|
---|
4617 | qWarning( "QDomText::splitText The node has no parent. So I can not split" );
|
---|
4618 | return 0;
|
---|
4619 | }
|
---|
4620 |
|
---|
4621 | QDomTextPrivate* t = new QDomTextPrivate( ownerDocument(), 0, value.mid( offset ) );
|
---|
4622 | value.truncate( offset );
|
---|
4623 |
|
---|
4624 | parent()->insertAfter( t, this );
|
---|
4625 |
|
---|
4626 | return t;
|
---|
4627 | }
|
---|
4628 |
|
---|
4629 | void QDomTextPrivate::save( QTextStream& s, int, int ) const
|
---|
4630 | {
|
---|
4631 | s << encodeAttr( value );
|
---|
4632 | }
|
---|
4633 |
|
---|
4634 | /**************************************************************
|
---|
4635 | *
|
---|
4636 | * QDomText
|
---|
4637 | *
|
---|
4638 | **************************************************************/
|
---|
4639 |
|
---|
4640 | #define IMPL ((QDomTextPrivate*)impl)
|
---|
4641 |
|
---|
4642 | /*!
|
---|
4643 | \class QDomText qdom.h
|
---|
4644 | \reentrant
|
---|
4645 | \brief The QDomText class represents text data in the parsed XML document.
|
---|
4646 | \if defined(commercial)
|
---|
4647 | It is part of the <a href="commercialeditions.html">Qt Enterprise Edition</a>.
|
---|
4648 | \endif
|
---|
4649 |
|
---|
4650 | \module XML
|
---|
4651 | \ingroup xml-tools
|
---|
4652 |
|
---|
4653 | You can split the text in a QDomText object over two QDomText
|
---|
4654 | objecs with splitText().
|
---|
4655 |
|
---|
4656 | For further information about the Document Object Model see
|
---|
4657 | \link http://www.w3.org/TR/REC-DOM-Level-1/\endlink and
|
---|
4658 | \link http://www.w3.org/TR/DOM-Level-2-Core/\endlink.
|
---|
4659 | For a more general introduction of the DOM implementation see the
|
---|
4660 | QDomDocument documentation.
|
---|
4661 | */
|
---|
4662 |
|
---|
4663 | /*!
|
---|
4664 | Constructs an empty QDomText object.
|
---|
4665 |
|
---|
4666 | To construct a QDomText with content, use QDomDocument::createTextNode().
|
---|
4667 | */
|
---|
4668 | QDomText::QDomText()
|
---|
4669 | : QDomCharacterData()
|
---|
4670 | {
|
---|
4671 | }
|
---|
4672 |
|
---|
4673 | /*!
|
---|
4674 | Constructs a copy of \a x.
|
---|
4675 |
|
---|
4676 | The data of the copy is shared (shallow copy): modifying one node
|
---|
4677 | will also change the other. If you want to make a deep copy, use
|
---|
4678 | cloneNode().
|
---|
4679 | */
|
---|
4680 | QDomText::QDomText( const QDomText& x )
|
---|
4681 | : QDomCharacterData( x )
|
---|
4682 | {
|
---|
4683 | }
|
---|
4684 |
|
---|
4685 | QDomText::QDomText( QDomTextPrivate* n )
|
---|
4686 | : QDomCharacterData( n )
|
---|
4687 | {
|
---|
4688 | }
|
---|
4689 |
|
---|
4690 | /*!
|
---|
4691 | Assigns \a x to this DOM text.
|
---|
4692 |
|
---|
4693 | The data of the copy is shared (shallow copy): modifying one node
|
---|
4694 | will also change the other. If you want to make a deep copy, use
|
---|
4695 | cloneNode().
|
---|
4696 | */
|
---|
4697 | QDomText& QDomText::operator= ( const QDomText& x )
|
---|
4698 | {
|
---|
4699 | return (QDomText&) QDomNode::operator=( x );
|
---|
4700 | }
|
---|
4701 |
|
---|
4702 | /*!
|
---|
4703 | Destroys the object and frees its resources.
|
---|
4704 | */
|
---|
4705 | QDomText::~QDomText()
|
---|
4706 | {
|
---|
4707 | }
|
---|
4708 |
|
---|
4709 | /*!
|
---|
4710 | Returns \c TextNode.
|
---|
4711 | */
|
---|
4712 | QDomNode::NodeType QDomText::nodeType() const
|
---|
4713 | {
|
---|
4714 | return TextNode;
|
---|
4715 | }
|
---|
4716 |
|
---|
4717 | /*!
|
---|
4718 | Splits this DOM text object into two QDomText objects. This object
|
---|
4719 | keeps its first \a offset characters and the second (newly
|
---|
4720 | created) object is inserted into the document tree after this
|
---|
4721 | object with the remaining characters.
|
---|
4722 |
|
---|
4723 | The function returns the newly created object.
|
---|
4724 |
|
---|
4725 | \sa QDomNode::normalize()
|
---|
4726 | */
|
---|
4727 | QDomText QDomText::splitText( int offset )
|
---|
4728 | {
|
---|
4729 | if ( !impl )
|
---|
4730 | return QDomText();
|
---|
4731 | return QDomText( IMPL->splitText( offset ) );
|
---|
4732 | }
|
---|
4733 |
|
---|
4734 | /*!
|
---|
4735 | Returns TRUE.
|
---|
4736 | */
|
---|
4737 | bool QDomText::isText() const
|
---|
4738 | {
|
---|
4739 | return TRUE;
|
---|
4740 | }
|
---|
4741 |
|
---|
4742 | #undef IMPL
|
---|
4743 |
|
---|
4744 | /**************************************************************
|
---|
4745 | *
|
---|
4746 | * QDomCommentPrivate
|
---|
4747 | *
|
---|
4748 | **************************************************************/
|
---|
4749 |
|
---|
4750 | QDomCommentPrivate::QDomCommentPrivate( QDomDocumentPrivate* d, QDomNodePrivate* parent, const QString& value )
|
---|
4751 | : QDomCharacterDataPrivate( d, parent, value )
|
---|
4752 | {
|
---|
4753 | name = "#comment";
|
---|
4754 | }
|
---|
4755 |
|
---|
4756 | QDomCommentPrivate::QDomCommentPrivate( QDomCommentPrivate* n, bool deep )
|
---|
4757 | : QDomCharacterDataPrivate( n, deep )
|
---|
4758 | {
|
---|
4759 | }
|
---|
4760 |
|
---|
4761 | QDomCommentPrivate::~QDomCommentPrivate()
|
---|
4762 | {
|
---|
4763 | }
|
---|
4764 |
|
---|
4765 | QDomNodePrivate* QDomCommentPrivate::cloneNode( bool deep)
|
---|
4766 | {
|
---|
4767 | QDomNodePrivate* p = new QDomCommentPrivate( this, deep );
|
---|
4768 | // We are not interested in this node
|
---|
4769 | p->deref();
|
---|
4770 | return p;
|
---|
4771 | }
|
---|
4772 |
|
---|
4773 | void QDomCommentPrivate::save( QTextStream& s, int, int ) const
|
---|
4774 | {
|
---|
4775 | s << "<!--" << value << "-->";
|
---|
4776 | }
|
---|
4777 |
|
---|
4778 | /**************************************************************
|
---|
4779 | *
|
---|
4780 | * QDomComment
|
---|
4781 | *
|
---|
4782 | **************************************************************/
|
---|
4783 |
|
---|
4784 | #define IMPL ((QDomCommentPrivate*)impl)
|
---|
4785 |
|
---|
4786 | /*!
|
---|
4787 | \class QDomComment qdom.h
|
---|
4788 | \reentrant
|
---|
4789 | \brief The QDomComment class represents an XML comment.
|
---|
4790 | \if defined(commercial)
|
---|
4791 | It is part of the <a href="commercialeditions.html">Qt Enterprise Edition</a>.
|
---|
4792 | \endif
|
---|
4793 |
|
---|
4794 | \module XML
|
---|
4795 | \ingroup xml-tools
|
---|
4796 |
|
---|
4797 | A comment in the parsed XML such as this:
|
---|
4798 | \code
|
---|
4799 | <!-- this is a comment -->
|
---|
4800 | \endcode
|
---|
4801 | is represented by QDomComment objects in the parsed Dom tree.
|
---|
4802 |
|
---|
4803 | For further information about the Document Object Model see
|
---|
4804 | \link http://www.w3.org/TR/REC-DOM-Level-1/\endlink and
|
---|
4805 | \link http://www.w3.org/TR/DOM-Level-2-Core/\endlink.
|
---|
4806 | For a more general introduction of the DOM implementation see the
|
---|
4807 | QDomDocument documentation.
|
---|
4808 | */
|
---|
4809 |
|
---|
4810 | /*!
|
---|
4811 | Constructs an empty comment. To construct a comment with content,
|
---|
4812 | use the QDomDocument::createComment() function.
|
---|
4813 | */
|
---|
4814 | QDomComment::QDomComment()
|
---|
4815 | : QDomCharacterData()
|
---|
4816 | {
|
---|
4817 | }
|
---|
4818 |
|
---|
4819 | /*!
|
---|
4820 | Constructs a copy of \a x.
|
---|
4821 |
|
---|
4822 | The data of the copy is shared (shallow copy): modifying one node
|
---|
4823 | will also change the other. If you want to make a deep copy, use
|
---|
4824 | cloneNode().
|
---|
4825 | */
|
---|
4826 | QDomComment::QDomComment( const QDomComment& x )
|
---|
4827 | : QDomCharacterData( x )
|
---|
4828 | {
|
---|
4829 | }
|
---|
4830 |
|
---|
4831 | QDomComment::QDomComment( QDomCommentPrivate* n )
|
---|
4832 | : QDomCharacterData( n )
|
---|
4833 | {
|
---|
4834 | }
|
---|
4835 |
|
---|
4836 | /*!
|
---|
4837 | Assigns \a x to this DOM comment.
|
---|
4838 |
|
---|
4839 | The data of the copy is shared (shallow copy): modifying one node
|
---|
4840 | will also change the other. If you want to make a deep copy, use
|
---|
4841 | cloneNode().
|
---|
4842 | */
|
---|
4843 | QDomComment& QDomComment::operator= ( const QDomComment& x )
|
---|
4844 | {
|
---|
4845 | return (QDomComment&) QDomNode::operator=( x );
|
---|
4846 | }
|
---|
4847 |
|
---|
4848 | /*!
|
---|
4849 | Destroys the object and frees its resources.
|
---|
4850 | */
|
---|
4851 | QDomComment::~QDomComment()
|
---|
4852 | {
|
---|
4853 | }
|
---|
4854 |
|
---|
4855 | /*!
|
---|
4856 | Returns \c CommentNode.
|
---|
4857 | */
|
---|
4858 | QDomNode::NodeType QDomComment::nodeType() const
|
---|
4859 | {
|
---|
4860 | return CommentNode;
|
---|
4861 | }
|
---|
4862 |
|
---|
4863 | /*!
|
---|
4864 | Returns TRUE.
|
---|
4865 | */
|
---|
4866 | bool QDomComment::isComment() const
|
---|
4867 | {
|
---|
4868 | return TRUE;
|
---|
4869 | }
|
---|
4870 |
|
---|
4871 | #undef IMPL
|
---|
4872 |
|
---|
4873 | /**************************************************************
|
---|
4874 | *
|
---|
4875 | * QDomCDATASectionPrivate
|
---|
4876 | *
|
---|
4877 | **************************************************************/
|
---|
4878 |
|
---|
4879 | QDomCDATASectionPrivate::QDomCDATASectionPrivate( QDomDocumentPrivate* d, QDomNodePrivate* parent,
|
---|
4880 | const QString& value )
|
---|
4881 | : QDomTextPrivate( d, parent, value )
|
---|
4882 | {
|
---|
4883 | name = "#cdata-section";
|
---|
4884 | }
|
---|
4885 |
|
---|
4886 | QDomCDATASectionPrivate::QDomCDATASectionPrivate( QDomCDATASectionPrivate* n, bool deep )
|
---|
4887 | : QDomTextPrivate( n, deep )
|
---|
4888 | {
|
---|
4889 | }
|
---|
4890 |
|
---|
4891 | QDomCDATASectionPrivate::~QDomCDATASectionPrivate()
|
---|
4892 | {
|
---|
4893 | }
|
---|
4894 |
|
---|
4895 | QDomNodePrivate* QDomCDATASectionPrivate::cloneNode( bool deep)
|
---|
4896 | {
|
---|
4897 | QDomNodePrivate* p = new QDomCDATASectionPrivate( this, deep );
|
---|
4898 | // We are not interested in this node
|
---|
4899 | p->deref();
|
---|
4900 | return p;
|
---|
4901 | }
|
---|
4902 |
|
---|
4903 | void QDomCDATASectionPrivate::save( QTextStream& s, int, int ) const
|
---|
4904 | {
|
---|
4905 | // ### How do we escape "]]>" ?
|
---|
4906 | // "]]>" is not allowed; so there should be none in value anyway
|
---|
4907 | s << "<![CDATA[" << value << "]]>";
|
---|
4908 | }
|
---|
4909 |
|
---|
4910 | /**************************************************************
|
---|
4911 | *
|
---|
4912 | * QDomCDATASection
|
---|
4913 | *
|
---|
4914 | **************************************************************/
|
---|
4915 |
|
---|
4916 | #define IMPL ((QDomCDATASectionPrivate*)impl)
|
---|
4917 |
|
---|
4918 | /*!
|
---|
4919 | \class QDomCDATASection qdom.h
|
---|
4920 | \reentrant
|
---|
4921 | \brief The QDomCDATASection class represents an XML CDATA section.
|
---|
4922 | \if defined(commercial)
|
---|
4923 | It is part of the <a href="commercialeditions.html">Qt Enterprise Edition</a>.
|
---|
4924 | \endif
|
---|
4925 |
|
---|
4926 | \module XML
|
---|
4927 | \ingroup xml-tools
|
---|
4928 |
|
---|
4929 | CDATA sections are used to escape blocks of text containing
|
---|
4930 | characters that would otherwise be regarded as markup. The only
|
---|
4931 | delimiter that is recognized in a CDATA section is the "]]>"
|
---|
4932 | string that terminates the CDATA section. CDATA sections cannot be
|
---|
4933 | nested. Their primary purpose is for including material such as
|
---|
4934 | XML fragments, without needing to escape all the delimiters.
|
---|
4935 |
|
---|
4936 | Adjacent QDomCDATASection nodes are not merged by the
|
---|
4937 | QDomNode::normalize() function.
|
---|
4938 |
|
---|
4939 | For further information about the Document Object Model see
|
---|
4940 | \link http://www.w3.org/TR/REC-DOM-Level-1/\endlink and
|
---|
4941 | \link http://www.w3.org/TR/DOM-Level-2-Core/\endlink.
|
---|
4942 | For a more general introduction of the DOM implementation see the
|
---|
4943 | QDomDocument documentation.
|
---|
4944 | */
|
---|
4945 |
|
---|
4946 | /*!
|
---|
4947 | Constructs an empty CDATA section. To create a CDATA section with
|
---|
4948 | content, use the QDomDocument::createCDATASection() function.
|
---|
4949 | */
|
---|
4950 | QDomCDATASection::QDomCDATASection()
|
---|
4951 | : QDomText()
|
---|
4952 | {
|
---|
4953 | }
|
---|
4954 |
|
---|
4955 | /*!
|
---|
4956 | Constructs a copy of \a x.
|
---|
4957 |
|
---|
4958 | The data of the copy is shared (shallow copy): modifying one node
|
---|
4959 | will also change the other. If you want to make a deep copy, use
|
---|
4960 | cloneNode().
|
---|
4961 | */
|
---|
4962 | QDomCDATASection::QDomCDATASection( const QDomCDATASection& x )
|
---|
4963 | : QDomText( x )
|
---|
4964 | {
|
---|
4965 | }
|
---|
4966 |
|
---|
4967 | QDomCDATASection::QDomCDATASection( QDomCDATASectionPrivate* n )
|
---|
4968 | : QDomText( n )
|
---|
4969 | {
|
---|
4970 | }
|
---|
4971 |
|
---|
4972 | /*!
|
---|
4973 | Assigns \a x to this CDATA section.
|
---|
4974 |
|
---|
4975 | The data of the copy is shared (shallow copy): modifying one node
|
---|
4976 | will also change the other. If you want to make a deep copy, use
|
---|
4977 | cloneNode().
|
---|
4978 | */
|
---|
4979 | QDomCDATASection& QDomCDATASection::operator= ( const QDomCDATASection& x )
|
---|
4980 | {
|
---|
4981 | return (QDomCDATASection&) QDomNode::operator=( x );
|
---|
4982 | }
|
---|
4983 |
|
---|
4984 | /*!
|
---|
4985 | Destroys the object and frees its resources.
|
---|
4986 | */
|
---|
4987 | QDomCDATASection::~QDomCDATASection()
|
---|
4988 | {
|
---|
4989 | }
|
---|
4990 |
|
---|
4991 | /*!
|
---|
4992 | Returns \c CDATASection.
|
---|
4993 | */
|
---|
4994 | QDomNode::NodeType QDomCDATASection::nodeType() const
|
---|
4995 | {
|
---|
4996 | return CDATASectionNode;
|
---|
4997 | }
|
---|
4998 |
|
---|
4999 | /*!
|
---|
5000 | Returns TRUE.
|
---|
5001 | */
|
---|
5002 | bool QDomCDATASection::isCDATASection() const
|
---|
5003 | {
|
---|
5004 | return TRUE;
|
---|
5005 | }
|
---|
5006 |
|
---|
5007 | #undef IMPL
|
---|
5008 |
|
---|
5009 | /**************************************************************
|
---|
5010 | *
|
---|
5011 | * QDomNotationPrivate
|
---|
5012 | *
|
---|
5013 | **************************************************************/
|
---|
5014 |
|
---|
5015 | QDomNotationPrivate::QDomNotationPrivate( QDomDocumentPrivate* d, QDomNodePrivate* parent,
|
---|
5016 | const QString& aname,
|
---|
5017 | const QString& pub, const QString& sys )
|
---|
5018 | : QDomNodePrivate( d, parent )
|
---|
5019 | {
|
---|
5020 | name = aname;
|
---|
5021 | m_pub = pub;
|
---|
5022 | m_sys = sys;
|
---|
5023 | }
|
---|
5024 |
|
---|
5025 | QDomNotationPrivate::QDomNotationPrivate( QDomNotationPrivate* n, bool deep )
|
---|
5026 | : QDomNodePrivate( n, deep )
|
---|
5027 | {
|
---|
5028 | m_sys = n->m_sys;
|
---|
5029 | m_pub = n->m_pub;
|
---|
5030 | }
|
---|
5031 |
|
---|
5032 | QDomNotationPrivate::~QDomNotationPrivate()
|
---|
5033 | {
|
---|
5034 | }
|
---|
5035 |
|
---|
5036 | QDomNodePrivate* QDomNotationPrivate::cloneNode( bool deep)
|
---|
5037 | {
|
---|
5038 | QDomNodePrivate* p = new QDomNotationPrivate( this, deep );
|
---|
5039 | // We are not interested in this node
|
---|
5040 | p->deref();
|
---|
5041 | return p;
|
---|
5042 | }
|
---|
5043 |
|
---|
5044 | void QDomNotationPrivate::save( QTextStream& s, int, int ) const
|
---|
5045 | {
|
---|
5046 | s << "<!NOTATION " << name << " ";
|
---|
5047 | if ( !m_pub.isNull() ) {
|
---|
5048 | s << "PUBLIC \"" << m_pub << "\"";
|
---|
5049 | if ( !m_sys.isNull() )
|
---|
5050 | s << " \"" << m_sys << "\"";
|
---|
5051 | } else {
|
---|
5052 | s << "SYSTEM \"" << m_sys << "\"";
|
---|
5053 | }
|
---|
5054 | s << ">" << endl;
|
---|
5055 | }
|
---|
5056 |
|
---|
5057 | /**************************************************************
|
---|
5058 | *
|
---|
5059 | * QDomNotation
|
---|
5060 | *
|
---|
5061 | **************************************************************/
|
---|
5062 |
|
---|
5063 | #define IMPL ((QDomNotationPrivate*)impl)
|
---|
5064 |
|
---|
5065 | /*!
|
---|
5066 | \class QDomNotation qdom.h
|
---|
5067 | \reentrant
|
---|
5068 | \brief The QDomNotation class represents an XML notation.
|
---|
5069 | \if defined(commercial)
|
---|
5070 | It is part of the <a href="commercialeditions.html">Qt Enterprise Edition</a>.
|
---|
5071 | \endif
|
---|
5072 |
|
---|
5073 | \module XML
|
---|
5074 | \ingroup xml-tools
|
---|
5075 |
|
---|
5076 | A notation either declares, by name, the format of an unparsed
|
---|
5077 | entity (see section 4.7 of the XML 1.0 specification), or is used
|
---|
5078 | for formal declaration of processing instruction targets (see
|
---|
5079 | section 2.6 of the XML 1.0 specification).
|
---|
5080 |
|
---|
5081 | DOM does not support editing notation nodes; they are therefore
|
---|
5082 | read-only.
|
---|
5083 |
|
---|
5084 | A notation node does not have any parent.
|
---|
5085 |
|
---|
5086 | You can retrieve the publicId() and systemId() from a notation
|
---|
5087 | node.
|
---|
5088 |
|
---|
5089 | For further information about the Document Object Model see
|
---|
5090 | \link http://www.w3.org/TR/REC-DOM-Level-1/\endlink and
|
---|
5091 | \link http://www.w3.org/TR/DOM-Level-2-Core/\endlink.
|
---|
5092 | For a more general introduction of the DOM implementation see the
|
---|
5093 | QDomDocument documentation.
|
---|
5094 | */
|
---|
5095 |
|
---|
5096 |
|
---|
5097 | /*!
|
---|
5098 | Constructor.
|
---|
5099 | */
|
---|
5100 | QDomNotation::QDomNotation()
|
---|
5101 | : QDomNode()
|
---|
5102 | {
|
---|
5103 | }
|
---|
5104 |
|
---|
5105 | /*!
|
---|
5106 | Constructs a copy of \a x.
|
---|
5107 |
|
---|
5108 | The data of the copy is shared (shallow copy): modifying one node
|
---|
5109 | will also change the other. If you want to make a deep copy, use
|
---|
5110 | cloneNode().
|
---|
5111 | */
|
---|
5112 | QDomNotation::QDomNotation( const QDomNotation& x )
|
---|
5113 | : QDomNode( x )
|
---|
5114 | {
|
---|
5115 | }
|
---|
5116 |
|
---|
5117 | QDomNotation::QDomNotation( QDomNotationPrivate* n )
|
---|
5118 | : QDomNode( n )
|
---|
5119 | {
|
---|
5120 | }
|
---|
5121 |
|
---|
5122 | /*!
|
---|
5123 | Assigns \a x to this DOM notation.
|
---|
5124 |
|
---|
5125 | The data of the copy is shared (shallow copy): modifying one node
|
---|
5126 | will also change the other. If you want to make a deep copy, use
|
---|
5127 | cloneNode().
|
---|
5128 | */
|
---|
5129 | QDomNotation& QDomNotation::operator= ( const QDomNotation& x )
|
---|
5130 | {
|
---|
5131 | return (QDomNotation&) QDomNode::operator=( x );
|
---|
5132 | }
|
---|
5133 |
|
---|
5134 | /*!
|
---|
5135 | Destroys the object and frees its resources.
|
---|
5136 | */
|
---|
5137 | QDomNotation::~QDomNotation()
|
---|
5138 | {
|
---|
5139 | }
|
---|
5140 |
|
---|
5141 | /*!
|
---|
5142 | Returns \c NotationNode.
|
---|
5143 | */
|
---|
5144 | QDomNode::NodeType QDomNotation::nodeType() const
|
---|
5145 | {
|
---|
5146 | return NotationNode;
|
---|
5147 | }
|
---|
5148 |
|
---|
5149 | /*!
|
---|
5150 | Returns the public identifier of this notation.
|
---|
5151 | */
|
---|
5152 | QString QDomNotation::publicId() const
|
---|
5153 | {
|
---|
5154 | if ( !impl )
|
---|
5155 | return QString::null;
|
---|
5156 | return IMPL->m_pub;
|
---|
5157 | }
|
---|
5158 |
|
---|
5159 | /*!
|
---|
5160 | Returns the system identifier of this notation.
|
---|
5161 | */
|
---|
5162 | QString QDomNotation::systemId() const
|
---|
5163 | {
|
---|
5164 | if ( !impl )
|
---|
5165 | return QString::null;
|
---|
5166 | return IMPL->m_sys;
|
---|
5167 | }
|
---|
5168 |
|
---|
5169 | /*!
|
---|
5170 | Returns TRUE.
|
---|
5171 | */
|
---|
5172 | bool QDomNotation::isNotation() const
|
---|
5173 | {
|
---|
5174 | return TRUE;
|
---|
5175 | }
|
---|
5176 |
|
---|
5177 | #undef IMPL
|
---|
5178 |
|
---|
5179 | /**************************************************************
|
---|
5180 | *
|
---|
5181 | * QDomEntityPrivate
|
---|
5182 | *
|
---|
5183 | **************************************************************/
|
---|
5184 |
|
---|
5185 | QDomEntityPrivate::QDomEntityPrivate( QDomDocumentPrivate* d, QDomNodePrivate* parent,
|
---|
5186 | const QString& aname,
|
---|
5187 | const QString& pub, const QString& sys, const QString& notation )
|
---|
5188 | : QDomNodePrivate( d, parent )
|
---|
5189 | {
|
---|
5190 | name = aname;
|
---|
5191 | m_pub = pub;
|
---|
5192 | m_sys = sys;
|
---|
5193 | m_notationName = notation;
|
---|
5194 | }
|
---|
5195 |
|
---|
5196 | QDomEntityPrivate::QDomEntityPrivate( QDomEntityPrivate* n, bool deep )
|
---|
5197 | : QDomNodePrivate( n, deep )
|
---|
5198 | {
|
---|
5199 | m_sys = n->m_sys;
|
---|
5200 | m_pub = n->m_pub;
|
---|
5201 | m_notationName = n->m_notationName;
|
---|
5202 | }
|
---|
5203 |
|
---|
5204 | QDomEntityPrivate::~QDomEntityPrivate()
|
---|
5205 | {
|
---|
5206 | }
|
---|
5207 |
|
---|
5208 | QDomNodePrivate* QDomEntityPrivate::cloneNode( bool deep)
|
---|
5209 | {
|
---|
5210 | QDomNodePrivate* p = new QDomEntityPrivate( this, deep );
|
---|
5211 | // We are not interested in this node
|
---|
5212 | p->deref();
|
---|
5213 | return p;
|
---|
5214 | }
|
---|
5215 |
|
---|
5216 | /*
|
---|
5217 | Encode an entity value upon saving.
|
---|
5218 | */
|
---|
5219 | static QCString encodeEntity( const QCString& str )
|
---|
5220 | {
|
---|
5221 | QCString tmp( str );
|
---|
5222 | uint len = tmp.length();
|
---|
5223 | uint i = 0;
|
---|
5224 | const char* d = tmp.data();
|
---|
5225 | while ( i < len ) {
|
---|
5226 | if ( d[i] == '%' ){
|
---|
5227 | tmp.replace( i, 1, "<" );
|
---|
5228 | d = tmp.data();
|
---|
5229 | len += 4;
|
---|
5230 | i += 5;
|
---|
5231 | }
|
---|
5232 | else if ( d[i] == '"' ) {
|
---|
5233 | tmp.replace( i, 1, """ );
|
---|
5234 | d = tmp.data();
|
---|
5235 | len += 4;
|
---|
5236 | i += 5;
|
---|
5237 | } else if ( d[i] == '&' && i + 1 < len && d[i+1] == '#' ) {
|
---|
5238 | // Dont encode < or " or &custom;.
|
---|
5239 | // Only encode character references
|
---|
5240 | tmp.replace( i, 1, "&" );
|
---|
5241 | d = tmp.data();
|
---|
5242 | len += 4;
|
---|
5243 | i += 5;
|
---|
5244 | } else {
|
---|
5245 | ++i;
|
---|
5246 | }
|
---|
5247 | }
|
---|
5248 |
|
---|
5249 | return tmp;
|
---|
5250 | }
|
---|
5251 |
|
---|
5252 | void QDomEntityPrivate::save( QTextStream& s, int, int ) const
|
---|
5253 | {
|
---|
5254 | if ( m_sys.isNull() && m_pub.isNull() ) {
|
---|
5255 | s << "<!ENTITY " << name << " \"" << encodeEntity( value.utf8() ) << "\">" << endl;
|
---|
5256 | } else {
|
---|
5257 | s << "<!ENTITY " << name << " ";
|
---|
5258 | if ( m_pub.isNull() ) {
|
---|
5259 | s << "SYSTEM \"" << m_sys << "\"";
|
---|
5260 | } else {
|
---|
5261 | s << "PUBLIC \"" << m_pub << "\" \"" << m_sys << "\"";
|
---|
5262 | }
|
---|
5263 | if (! m_notationName.isNull() ) {
|
---|
5264 | s << " NDATA " << m_notationName;
|
---|
5265 | }
|
---|
5266 | s << ">" << endl;
|
---|
5267 | }
|
---|
5268 | }
|
---|
5269 |
|
---|
5270 | /**************************************************************
|
---|
5271 | *
|
---|
5272 | * QDomEntity
|
---|
5273 | *
|
---|
5274 | **************************************************************/
|
---|
5275 |
|
---|
5276 | #define IMPL ((QDomEntityPrivate*)impl)
|
---|
5277 |
|
---|
5278 | /*!
|
---|
5279 | \class QDomEntity qdom.h
|
---|
5280 | \reentrant
|
---|
5281 | \brief The QDomEntity class represents an XML entity.
|
---|
5282 | \if defined(commercial)
|
---|
5283 | It is part of the <a href="commercialeditions.html">Qt Enterprise Edition</a>.
|
---|
5284 | \endif
|
---|
5285 |
|
---|
5286 | \module XML
|
---|
5287 | \ingroup xml-tools
|
---|
5288 |
|
---|
5289 | This class represents an entity in an XML document, either parsed
|
---|
5290 | or unparsed. Note that this models the entity itself not the
|
---|
5291 | entity declaration.
|
---|
5292 |
|
---|
5293 | DOM does not support editing entity nodes; if a user wants to make
|
---|
5294 | changes to the contents of an entity, every related
|
---|
5295 | QDomEntityReference node must be replaced in the DOM tree by a
|
---|
5296 | clone of the entity's contents, and then the desired changes must
|
---|
5297 | be made to each of the clones instead. All the descendents of an
|
---|
5298 | entity node are read-only.
|
---|
5299 |
|
---|
5300 | An entity node does not have any parent.
|
---|
5301 |
|
---|
5302 | You can access the entity's publicId(), systemId() and
|
---|
5303 | notationName() when available.
|
---|
5304 |
|
---|
5305 | For further information about the Document Object Model see
|
---|
5306 | \link http://www.w3.org/TR/REC-DOM-Level-1/\endlink and
|
---|
5307 | \link http://www.w3.org/TR/DOM-Level-2-Core/\endlink.
|
---|
5308 | For a more general introduction of the DOM implementation see the
|
---|
5309 | QDomDocument documentation.
|
---|
5310 | */
|
---|
5311 |
|
---|
5312 |
|
---|
5313 | /*!
|
---|
5314 | Constructs an empty entity.
|
---|
5315 | */
|
---|
5316 | QDomEntity::QDomEntity()
|
---|
5317 | : QDomNode()
|
---|
5318 | {
|
---|
5319 | }
|
---|
5320 |
|
---|
5321 |
|
---|
5322 | /*!
|
---|
5323 | Constructs a copy of \a x.
|
---|
5324 |
|
---|
5325 | The data of the copy is shared (shallow copy): modifying one node
|
---|
5326 | will also change the other. If you want to make a deep copy, use
|
---|
5327 | cloneNode().
|
---|
5328 | */
|
---|
5329 | QDomEntity::QDomEntity( const QDomEntity& x )
|
---|
5330 | : QDomNode( x )
|
---|
5331 | {
|
---|
5332 | }
|
---|
5333 |
|
---|
5334 | QDomEntity::QDomEntity( QDomEntityPrivate* n )
|
---|
5335 | : QDomNode( n )
|
---|
5336 | {
|
---|
5337 | }
|
---|
5338 |
|
---|
5339 | /*!
|
---|
5340 | Assigns \a x to this DOM entity.
|
---|
5341 |
|
---|
5342 | The data of the copy is shared (shallow copy): modifying one node
|
---|
5343 | will also change the other. If you want to make a deep copy, use
|
---|
5344 | cloneNode().
|
---|
5345 | */
|
---|
5346 | QDomEntity& QDomEntity::operator= ( const QDomEntity& x )
|
---|
5347 | {
|
---|
5348 | return (QDomEntity&) QDomNode::operator=( x );
|
---|
5349 | }
|
---|
5350 |
|
---|
5351 | /*!
|
---|
5352 | Destroys the object and frees its resources.
|
---|
5353 | */
|
---|
5354 | QDomEntity::~QDomEntity()
|
---|
5355 | {
|
---|
5356 | }
|
---|
5357 |
|
---|
5358 | /*!
|
---|
5359 | Returns \c EntityNode.
|
---|
5360 | */
|
---|
5361 | QDomNode::NodeType QDomEntity::nodeType() const
|
---|
5362 | {
|
---|
5363 | return EntityNode;
|
---|
5364 | }
|
---|
5365 |
|
---|
5366 | /*!
|
---|
5367 | Returns the public identifier associated with this entity. If the
|
---|
5368 | public identifier was not specified QString::null is returned.
|
---|
5369 | */
|
---|
5370 | QString QDomEntity::publicId() const
|
---|
5371 | {
|
---|
5372 | if ( !impl )
|
---|
5373 | return QString::null;
|
---|
5374 | return IMPL->m_pub;
|
---|
5375 | }
|
---|
5376 |
|
---|
5377 | /*!
|
---|
5378 | Returns the system identifier associated with this entity. If the
|
---|
5379 | system identifier was not specified QString::null is returned.
|
---|
5380 | */
|
---|
5381 | QString QDomEntity::systemId() const
|
---|
5382 | {
|
---|
5383 | if ( !impl )
|
---|
5384 | return QString::null;
|
---|
5385 | return IMPL->m_sys;
|
---|
5386 | }
|
---|
5387 |
|
---|
5388 | /*!
|
---|
5389 | For unparsed entities this function returns the name of the
|
---|
5390 | notation for the entity. For parsed entities this function returns
|
---|
5391 | QString::null.
|
---|
5392 | */
|
---|
5393 | QString QDomEntity::notationName() const
|
---|
5394 | {
|
---|
5395 | if ( !impl )
|
---|
5396 | return QString::null;
|
---|
5397 | return IMPL->m_notationName;
|
---|
5398 | }
|
---|
5399 |
|
---|
5400 | /*!
|
---|
5401 | Returns TRUE.
|
---|
5402 | */
|
---|
5403 | bool QDomEntity::isEntity() const
|
---|
5404 | {
|
---|
5405 | return TRUE;
|
---|
5406 | }
|
---|
5407 |
|
---|
5408 | #undef IMPL
|
---|
5409 |
|
---|
5410 | /**************************************************************
|
---|
5411 | *
|
---|
5412 | * QDomEntityReferencePrivate
|
---|
5413 | *
|
---|
5414 | **************************************************************/
|
---|
5415 |
|
---|
5416 | QDomEntityReferencePrivate::QDomEntityReferencePrivate( QDomDocumentPrivate* d, QDomNodePrivate* parent, const QString& aname )
|
---|
5417 | : QDomNodePrivate( d, parent )
|
---|
5418 | {
|
---|
5419 | name = aname;
|
---|
5420 | }
|
---|
5421 |
|
---|
5422 | QDomEntityReferencePrivate::QDomEntityReferencePrivate( QDomNodePrivate* n, bool deep )
|
---|
5423 | : QDomNodePrivate( n, deep )
|
---|
5424 | {
|
---|
5425 | }
|
---|
5426 |
|
---|
5427 | QDomEntityReferencePrivate::~QDomEntityReferencePrivate()
|
---|
5428 | {
|
---|
5429 | }
|
---|
5430 |
|
---|
5431 | QDomNodePrivate* QDomEntityReferencePrivate::cloneNode( bool deep)
|
---|
5432 | {
|
---|
5433 | QDomNodePrivate* p = new QDomEntityReferencePrivate( this, deep );
|
---|
5434 | // We are not interested in this node
|
---|
5435 | p->deref();
|
---|
5436 | return p;
|
---|
5437 | }
|
---|
5438 |
|
---|
5439 | void QDomEntityReferencePrivate::save( QTextStream& s, int, int ) const
|
---|
5440 | {
|
---|
5441 | s << "&" << name << ";";
|
---|
5442 | }
|
---|
5443 |
|
---|
5444 | /**************************************************************
|
---|
5445 | *
|
---|
5446 | * QDomEntityReference
|
---|
5447 | *
|
---|
5448 | **************************************************************/
|
---|
5449 |
|
---|
5450 | #define IMPL ((QDomEntityReferencePrivate*)impl)
|
---|
5451 |
|
---|
5452 | /*!
|
---|
5453 | \class QDomEntityReference qdom.h
|
---|
5454 | \reentrant
|
---|
5455 | \brief The QDomEntityReference class represents an XML entity reference.
|
---|
5456 | \if defined(commercial)
|
---|
5457 | It is part of the <a href="commercialeditions.html">Qt Enterprise Edition</a>.
|
---|
5458 | \endif
|
---|
5459 |
|
---|
5460 | \module XML
|
---|
5461 | \ingroup xml-tools
|
---|
5462 |
|
---|
5463 | A QDomEntityReference object may be inserted into the DOM tree
|
---|
5464 | when an entity reference is in the source document, or when the
|
---|
5465 | user wishes to insert an entity reference.
|
---|
5466 |
|
---|
5467 | Note that character references and references to predefined
|
---|
5468 | entities are expanded by the XML processor so that characters are
|
---|
5469 | represented by their Unicode equivalent rather than by an entity
|
---|
5470 | reference.
|
---|
5471 |
|
---|
5472 | Moreover, the XML processor may completely expand references to
|
---|
5473 | entities while building the DOM tree, instead of providing
|
---|
5474 | QDomEntityReference objects.
|
---|
5475 |
|
---|
5476 | If it does provide such objects, then for a given entity reference
|
---|
5477 | node, it may be that there is no entity node representing the
|
---|
5478 | referenced entity; but if such an entity exists, then the child
|
---|
5479 | list of the entity reference node is the same as that of the
|
---|
5480 | entity node. As with the entity node, all descendents of the
|
---|
5481 | entity reference are read-only.
|
---|
5482 |
|
---|
5483 | For further information about the Document Object Model see
|
---|
5484 | \link http://www.w3.org/TR/REC-DOM-Level-1/\endlink and
|
---|
5485 | \link http://www.w3.org/TR/DOM-Level-2-Core/\endlink.
|
---|
5486 | For a more general introduction of the DOM implementation see the
|
---|
5487 | QDomDocument documentation.
|
---|
5488 | */
|
---|
5489 |
|
---|
5490 | /*!
|
---|
5491 | Constructs an empty entity reference. Use
|
---|
5492 | QDomDocument::createEntityReference() to create a entity reference
|
---|
5493 | with content.
|
---|
5494 | */
|
---|
5495 | QDomEntityReference::QDomEntityReference()
|
---|
5496 | : QDomNode()
|
---|
5497 | {
|
---|
5498 | }
|
---|
5499 |
|
---|
5500 | /*!
|
---|
5501 | Constructs a copy of \a x.
|
---|
5502 |
|
---|
5503 | The data of the copy is shared (shallow copy): modifying one node
|
---|
5504 | will also change the other. If you want to make a deep copy, use
|
---|
5505 | cloneNode().
|
---|
5506 | */
|
---|
5507 | QDomEntityReference::QDomEntityReference( const QDomEntityReference& x )
|
---|
5508 | : QDomNode( x )
|
---|
5509 | {
|
---|
5510 | }
|
---|
5511 |
|
---|
5512 | QDomEntityReference::QDomEntityReference( QDomEntityReferencePrivate* n )
|
---|
5513 | : QDomNode( n )
|
---|
5514 | {
|
---|
5515 | }
|
---|
5516 |
|
---|
5517 | /*!
|
---|
5518 | Assigns \a x to this entity reference.
|
---|
5519 |
|
---|
5520 | The data of the copy is shared (shallow copy): modifying one node
|
---|
5521 | will also change the other. If you want to make a deep copy, use
|
---|
5522 | cloneNode().
|
---|
5523 | */
|
---|
5524 | QDomEntityReference& QDomEntityReference::operator= ( const QDomEntityReference& x )
|
---|
5525 | {
|
---|
5526 | return (QDomEntityReference&) QDomNode::operator=( x );
|
---|
5527 | }
|
---|
5528 |
|
---|
5529 | /*!
|
---|
5530 | Destroys the object and frees its resources.
|
---|
5531 | */
|
---|
5532 | QDomEntityReference::~QDomEntityReference()
|
---|
5533 | {
|
---|
5534 | }
|
---|
5535 |
|
---|
5536 | /*!
|
---|
5537 | Returns \c EntityReference.
|
---|
5538 | */
|
---|
5539 | QDomNode::NodeType QDomEntityReference::nodeType() const
|
---|
5540 | {
|
---|
5541 | return EntityReferenceNode;
|
---|
5542 | }
|
---|
5543 |
|
---|
5544 | /*!
|
---|
5545 | Returns TRUE.
|
---|
5546 | */
|
---|
5547 | bool QDomEntityReference::isEntityReference() const
|
---|
5548 | {
|
---|
5549 | return TRUE;
|
---|
5550 | }
|
---|
5551 |
|
---|
5552 | #undef IMPL
|
---|
5553 |
|
---|
5554 | /**************************************************************
|
---|
5555 | *
|
---|
5556 | * QDomProcessingInstructionPrivate
|
---|
5557 | *
|
---|
5558 | **************************************************************/
|
---|
5559 |
|
---|
5560 | QDomProcessingInstructionPrivate::QDomProcessingInstructionPrivate( QDomDocumentPrivate* d,
|
---|
5561 | QDomNodePrivate* parent, const QString& target, const QString& data )
|
---|
5562 | : QDomNodePrivate( d, parent )
|
---|
5563 | {
|
---|
5564 | name = target;
|
---|
5565 | value = data;
|
---|
5566 | }
|
---|
5567 |
|
---|
5568 | QDomProcessingInstructionPrivate::QDomProcessingInstructionPrivate( QDomProcessingInstructionPrivate* n, bool deep )
|
---|
5569 | : QDomNodePrivate( n, deep )
|
---|
5570 | {
|
---|
5571 | }
|
---|
5572 |
|
---|
5573 | QDomProcessingInstructionPrivate::~QDomProcessingInstructionPrivate()
|
---|
5574 | {
|
---|
5575 | }
|
---|
5576 |
|
---|
5577 | QDomNodePrivate* QDomProcessingInstructionPrivate::cloneNode( bool deep)
|
---|
5578 | {
|
---|
5579 | QDomNodePrivate* p = new QDomProcessingInstructionPrivate( this, deep );
|
---|
5580 | // We are not interested in this node
|
---|
5581 | p->deref();
|
---|
5582 | return p;
|
---|
5583 | }
|
---|
5584 |
|
---|
5585 | void QDomProcessingInstructionPrivate::save( QTextStream& s, int, int ) const
|
---|
5586 | {
|
---|
5587 | s << "<?" << name << " " << value << "?>" << endl;
|
---|
5588 | }
|
---|
5589 |
|
---|
5590 | /**************************************************************
|
---|
5591 | *
|
---|
5592 | * QDomProcessingInstruction
|
---|
5593 | *
|
---|
5594 | **************************************************************/
|
---|
5595 |
|
---|
5596 | #define IMPL ((QDomProcessingInstructionPrivate*)impl)
|
---|
5597 |
|
---|
5598 | /*!
|
---|
5599 | \class QDomProcessingInstruction qdom.h
|
---|
5600 | \reentrant
|
---|
5601 | \brief The QDomProcessingInstruction class represents an XML processing
|
---|
5602 | instruction.
|
---|
5603 | \if defined(commercial)
|
---|
5604 | It is part of the <a href="commercialeditions.html">Qt Enterprise Edition</a>.
|
---|
5605 | \endif
|
---|
5606 |
|
---|
5607 | \module XML
|
---|
5608 | \ingroup xml-tools
|
---|
5609 |
|
---|
5610 | Processing instructions are used in XML to keep processor-specific
|
---|
5611 | information in the text of the document.
|
---|
5612 |
|
---|
5613 | The content of the processing instruction is retrieved with data()
|
---|
5614 | and set with setData(). The processing instruction's target is
|
---|
5615 | retrieved with target().
|
---|
5616 |
|
---|
5617 | For further information about the Document Object Model see
|
---|
5618 | \link http://www.w3.org/TR/REC-DOM-Level-1/\endlink and
|
---|
5619 | \link http://www.w3.org/TR/DOM-Level-2-Core/\endlink.
|
---|
5620 | For a more general introduction of the DOM implementation see the
|
---|
5621 | QDomDocument documentation.
|
---|
5622 | */
|
---|
5623 |
|
---|
5624 | /*!
|
---|
5625 | Constructs an empty processing instruction. Use
|
---|
5626 | QDomDocument::createProcessingInstruction() to create a processing
|
---|
5627 | instruction with content.
|
---|
5628 | */
|
---|
5629 | QDomProcessingInstruction::QDomProcessingInstruction()
|
---|
5630 | : QDomNode()
|
---|
5631 | {
|
---|
5632 | }
|
---|
5633 |
|
---|
5634 | /*!
|
---|
5635 | Constructs a copy of \a x.
|
---|
5636 |
|
---|
5637 | The data of the copy is shared (shallow copy): modifying one node
|
---|
5638 | will also change the other. If you want to make a deep copy, use
|
---|
5639 | cloneNode().
|
---|
5640 | */
|
---|
5641 | QDomProcessingInstruction::QDomProcessingInstruction( const QDomProcessingInstruction& x )
|
---|
5642 | : QDomNode( x )
|
---|
5643 | {
|
---|
5644 | }
|
---|
5645 |
|
---|
5646 | QDomProcessingInstruction::QDomProcessingInstruction( QDomProcessingInstructionPrivate* n )
|
---|
5647 | : QDomNode( n )
|
---|
5648 | {
|
---|
5649 | }
|
---|
5650 |
|
---|
5651 | /*!
|
---|
5652 | Assigns \a x to this processing instruction.
|
---|
5653 |
|
---|
5654 | The data of the copy is shared (shallow copy): modifying one node
|
---|
5655 | will also change the other. If you want to make a deep copy, use
|
---|
5656 | cloneNode().
|
---|
5657 | */
|
---|
5658 | QDomProcessingInstruction& QDomProcessingInstruction::operator= ( const QDomProcessingInstruction& x )
|
---|
5659 | {
|
---|
5660 | return (QDomProcessingInstruction&) QDomNode::operator=( x );
|
---|
5661 | }
|
---|
5662 |
|
---|
5663 | /*!
|
---|
5664 | Destroys the object and frees its resources.
|
---|
5665 | */
|
---|
5666 | QDomProcessingInstruction::~QDomProcessingInstruction()
|
---|
5667 | {
|
---|
5668 | }
|
---|
5669 |
|
---|
5670 | /*!
|
---|
5671 | Returns \c ProcessingInstructionNode.
|
---|
5672 | */
|
---|
5673 | QDomNode::NodeType QDomProcessingInstruction::nodeType() const
|
---|
5674 | {
|
---|
5675 | return ProcessingInstructionNode;
|
---|
5676 | }
|
---|
5677 |
|
---|
5678 | /*!
|
---|
5679 | Returns the target of this processing instruction.
|
---|
5680 |
|
---|
5681 | \sa data()
|
---|
5682 | */
|
---|
5683 | QString QDomProcessingInstruction::target() const
|
---|
5684 | {
|
---|
5685 | if ( !impl )
|
---|
5686 | return QString::null;
|
---|
5687 | return impl->nodeName();
|
---|
5688 | }
|
---|
5689 |
|
---|
5690 | /*!
|
---|
5691 | Returns the content of this processing instruction.
|
---|
5692 |
|
---|
5693 | \sa setData() target()
|
---|
5694 | */
|
---|
5695 | QString QDomProcessingInstruction::data() const
|
---|
5696 | {
|
---|
5697 | if ( !impl )
|
---|
5698 | return QString::null;
|
---|
5699 | return impl->nodeValue();
|
---|
5700 | }
|
---|
5701 |
|
---|
5702 | /*!
|
---|
5703 | Sets the data contained in the processing instruction to \a d.
|
---|
5704 |
|
---|
5705 | \sa data()
|
---|
5706 | */
|
---|
5707 | void QDomProcessingInstruction::setData( const QString& d )
|
---|
5708 | {
|
---|
5709 | if ( !impl )
|
---|
5710 | return;
|
---|
5711 | impl->setNodeValue( d );
|
---|
5712 | }
|
---|
5713 |
|
---|
5714 | /*!
|
---|
5715 | Returns TRUE.
|
---|
5716 | */
|
---|
5717 | bool QDomProcessingInstruction::isProcessingInstruction() const
|
---|
5718 | {
|
---|
5719 | return TRUE;
|
---|
5720 | }
|
---|
5721 |
|
---|
5722 | #undef IMPL
|
---|
5723 |
|
---|
5724 | /**************************************************************
|
---|
5725 | *
|
---|
5726 | * QDomDocumentPrivate
|
---|
5727 | *
|
---|
5728 | **************************************************************/
|
---|
5729 |
|
---|
5730 | QDomDocumentPrivate::QDomDocumentPrivate()
|
---|
5731 | : QDomNodePrivate( 0 )
|
---|
5732 | {
|
---|
5733 | impl = new QDomImplementationPrivate();
|
---|
5734 | type = new QDomDocumentTypePrivate( this, this );
|
---|
5735 |
|
---|
5736 | name = "#document";
|
---|
5737 | }
|
---|
5738 |
|
---|
5739 | QDomDocumentPrivate::QDomDocumentPrivate( const QString& aname )
|
---|
5740 | : QDomNodePrivate( 0 )
|
---|
5741 | {
|
---|
5742 | impl = new QDomImplementationPrivate();
|
---|
5743 | type = new QDomDocumentTypePrivate( this, this );
|
---|
5744 | type->name = aname;
|
---|
5745 |
|
---|
5746 | name = "#document";
|
---|
5747 | }
|
---|
5748 |
|
---|
5749 | QDomDocumentPrivate::QDomDocumentPrivate( QDomDocumentTypePrivate* dt )
|
---|
5750 | : QDomNodePrivate( 0 )
|
---|
5751 | {
|
---|
5752 | impl = new QDomImplementationPrivate();
|
---|
5753 | if ( dt != 0 ) {
|
---|
5754 | type = dt;
|
---|
5755 | type->ref();
|
---|
5756 | } else {
|
---|
5757 | type = new QDomDocumentTypePrivate( this, this );
|
---|
5758 | }
|
---|
5759 |
|
---|
5760 | name = "#document";
|
---|
5761 | }
|
---|
5762 |
|
---|
5763 | QDomDocumentPrivate::QDomDocumentPrivate( QDomDocumentPrivate* n, bool deep )
|
---|
5764 | : QDomNodePrivate( n, deep )
|
---|
5765 | {
|
---|
5766 | impl = n->impl->clone();
|
---|
5767 | // Reference count is down to 0, so we set it to 1 here.
|
---|
5768 | impl->ref();
|
---|
5769 | type = (QDomDocumentTypePrivate*)n->type->cloneNode();
|
---|
5770 | type->setParent( this );
|
---|
5771 | // Reference count is down to 0, so we set it to 1 here.
|
---|
5772 | type->ref();
|
---|
5773 | }
|
---|
5774 |
|
---|
5775 | QDomDocumentPrivate::~QDomDocumentPrivate()
|
---|
5776 | {
|
---|
5777 | if ( impl->deref() ) delete impl;
|
---|
5778 | if ( type->deref() ) delete type;
|
---|
5779 | }
|
---|
5780 |
|
---|
5781 | void QDomDocumentPrivate::clear()
|
---|
5782 | {
|
---|
5783 | if ( impl->deref() ) delete impl;
|
---|
5784 | if ( type->deref() ) delete type;
|
---|
5785 | impl = 0;
|
---|
5786 | type = 0;
|
---|
5787 | QDomNodePrivate::clear();
|
---|
5788 | }
|
---|
5789 |
|
---|
5790 | bool QDomDocumentPrivate::setContent( QXmlInputSource *source, bool namespaceProcessing, QString *errorMsg, int *errorLine, int *errorColumn )
|
---|
5791 | {
|
---|
5792 | QXmlSimpleReader reader;
|
---|
5793 | if ( namespaceProcessing ) {
|
---|
5794 | reader.setFeature( "http://xml.org/sax/features/namespaces", TRUE );
|
---|
5795 | reader.setFeature( "http://xml.org/sax/features/namespace-prefixes", FALSE );
|
---|
5796 | } else {
|
---|
5797 | reader.setFeature( "http://xml.org/sax/features/namespaces", FALSE );
|
---|
5798 | reader.setFeature( "http://xml.org/sax/features/namespace-prefixes", TRUE );
|
---|
5799 | }
|
---|
5800 | reader.setFeature( "http://trolltech.com/xml/features/report-whitespace-only-CharData", FALSE );
|
---|
5801 |
|
---|
5802 | return setContent( source, &reader, errorMsg, errorLine, errorColumn );
|
---|
5803 | }
|
---|
5804 |
|
---|
5805 | bool QDomDocumentPrivate::setContent( QXmlInputSource *source, QXmlReader *reader, QString *errorMsg, int *errorLine, int *errorColumn )
|
---|
5806 | {
|
---|
5807 | clear();
|
---|
5808 | impl = new QDomImplementationPrivate;
|
---|
5809 | type = new QDomDocumentTypePrivate( this, this );
|
---|
5810 |
|
---|
5811 | bool namespaceProcessing = reader->feature( "http://xml.org/sax/features/namespaces" )
|
---|
5812 | && !reader->feature( "http://xml.org/sax/features/namespace-prefixes" );
|
---|
5813 |
|
---|
5814 | QDomHandler hnd( this, namespaceProcessing );
|
---|
5815 | reader->setContentHandler( &hnd );
|
---|
5816 | reader->setErrorHandler( &hnd );
|
---|
5817 | reader->setLexicalHandler( &hnd );
|
---|
5818 | reader->setDeclHandler( &hnd );
|
---|
5819 | reader->setDTDHandler( &hnd );
|
---|
5820 |
|
---|
5821 | if ( !reader->parse( source ) ) {
|
---|
5822 | if ( errorMsg )
|
---|
5823 | *errorMsg = hnd.errorMsg;
|
---|
5824 | if ( errorLine )
|
---|
5825 | *errorLine = hnd.errorLine;
|
---|
5826 | if ( errorColumn )
|
---|
5827 | *errorColumn = hnd.errorColumn;
|
---|
5828 | return FALSE;
|
---|
5829 | }
|
---|
5830 |
|
---|
5831 | return TRUE;
|
---|
5832 | }
|
---|
5833 |
|
---|
5834 | QDomNodePrivate* QDomDocumentPrivate::cloneNode( bool deep)
|
---|
5835 | {
|
---|
5836 | QDomNodePrivate* p = new QDomDocumentPrivate( this, deep );
|
---|
5837 | // We are not interested in this node
|
---|
5838 | p->deref();
|
---|
5839 | return p;
|
---|
5840 | }
|
---|
5841 |
|
---|
5842 | QDomElementPrivate* QDomDocumentPrivate::documentElement()
|
---|
5843 | {
|
---|
5844 | QDomNodePrivate* p = first;
|
---|
5845 | while ( p && !p->isElement() )
|
---|
5846 | p = p->next;
|
---|
5847 |
|
---|
5848 | return (QDomElementPrivate*)p;
|
---|
5849 | }
|
---|
5850 |
|
---|
5851 | QDomElementPrivate* QDomDocumentPrivate::createElement( const QString& tagName )
|
---|
5852 | {
|
---|
5853 | QDomElementPrivate* e = new QDomElementPrivate( this, 0, tagName );
|
---|
5854 | e->deref();
|
---|
5855 | return e;
|
---|
5856 | }
|
---|
5857 |
|
---|
5858 | QDomElementPrivate* QDomDocumentPrivate::createElementNS( const QString& nsURI, const QString& qName )
|
---|
5859 | {
|
---|
5860 | QDomElementPrivate* e = new QDomElementPrivate( this, 0, nsURI, qName );
|
---|
5861 | e->deref();
|
---|
5862 | return e;
|
---|
5863 | }
|
---|
5864 |
|
---|
5865 | QDomDocumentFragmentPrivate* QDomDocumentPrivate::createDocumentFragment()
|
---|
5866 | {
|
---|
5867 | QDomDocumentFragmentPrivate* f = new QDomDocumentFragmentPrivate( this, (QDomNodePrivate*)0 );
|
---|
5868 | f->deref();
|
---|
5869 | return f;
|
---|
5870 | }
|
---|
5871 |
|
---|
5872 | QDomTextPrivate* QDomDocumentPrivate::createTextNode( const QString& data )
|
---|
5873 | {
|
---|
5874 | QDomTextPrivate* t = new QDomTextPrivate( this, 0, data );
|
---|
5875 | t->deref();
|
---|
5876 | return t;
|
---|
5877 | }
|
---|
5878 |
|
---|
5879 | QDomCommentPrivate* QDomDocumentPrivate::createComment( const QString& data )
|
---|
5880 | {
|
---|
5881 | QDomCommentPrivate* c = new QDomCommentPrivate( this, 0, data );
|
---|
5882 | c->deref();
|
---|
5883 | return c;
|
---|
5884 | }
|
---|
5885 |
|
---|
5886 | QDomCDATASectionPrivate* QDomDocumentPrivate::createCDATASection( const QString& data )
|
---|
5887 | {
|
---|
5888 | QDomCDATASectionPrivate* c = new QDomCDATASectionPrivate( this, 0, data );
|
---|
5889 | c->deref();
|
---|
5890 | return c;
|
---|
5891 | }
|
---|
5892 |
|
---|
5893 | QDomProcessingInstructionPrivate* QDomDocumentPrivate::createProcessingInstruction( const QString& target, const QString& data )
|
---|
5894 | {
|
---|
5895 | QDomProcessingInstructionPrivate* p = new QDomProcessingInstructionPrivate( this, 0, target, data );
|
---|
5896 | p->deref();
|
---|
5897 | return p;
|
---|
5898 | }
|
---|
5899 |
|
---|
5900 | QDomAttrPrivate* QDomDocumentPrivate::createAttribute( const QString& aname )
|
---|
5901 | {
|
---|
5902 | QDomAttrPrivate* a = new QDomAttrPrivate( this, 0, aname );
|
---|
5903 | a->deref();
|
---|
5904 | return a;
|
---|
5905 | }
|
---|
5906 |
|
---|
5907 | QDomAttrPrivate* QDomDocumentPrivate::createAttributeNS( const QString& nsURI, const QString& qName )
|
---|
5908 | {
|
---|
5909 | QDomAttrPrivate* a = new QDomAttrPrivate( this, 0, nsURI, qName );
|
---|
5910 | a->deref();
|
---|
5911 | return a;
|
---|
5912 | }
|
---|
5913 |
|
---|
5914 | QDomEntityReferencePrivate* QDomDocumentPrivate::createEntityReference( const QString& aname )
|
---|
5915 | {
|
---|
5916 | QDomEntityReferencePrivate* e = new QDomEntityReferencePrivate( this, 0, aname );
|
---|
5917 | e->deref();
|
---|
5918 | return e;
|
---|
5919 | }
|
---|
5920 |
|
---|
5921 | QDomNodePrivate* QDomDocumentPrivate::importNode( const QDomNodePrivate* importedNode, bool deep )
|
---|
5922 | {
|
---|
5923 | QDomNodePrivate *node = 0;
|
---|
5924 | switch ( importedNode->nodeType() ) {
|
---|
5925 | case QDomNode::AttributeNode:
|
---|
5926 | node = new QDomAttrPrivate( (QDomAttrPrivate*)importedNode, TRUE );
|
---|
5927 | break;
|
---|
5928 | case QDomNode::DocumentFragmentNode:
|
---|
5929 | node = new QDomDocumentFragmentPrivate( (QDomDocumentFragmentPrivate*)importedNode, deep );
|
---|
5930 | break;
|
---|
5931 | case QDomNode::ElementNode:
|
---|
5932 | node = new QDomElementPrivate( (QDomElementPrivate*)importedNode, deep );
|
---|
5933 | break;
|
---|
5934 | case QDomNode::EntityNode:
|
---|
5935 | node = new QDomEntityPrivate( (QDomEntityPrivate*)importedNode, deep );
|
---|
5936 | break;
|
---|
5937 | case QDomNode::EntityReferenceNode:
|
---|
5938 | node = new QDomEntityReferencePrivate( (QDomEntityReferencePrivate*)importedNode, FALSE );
|
---|
5939 | break;
|
---|
5940 | case QDomNode::NotationNode:
|
---|
5941 | node = new QDomNotationPrivate( (QDomNotationPrivate*)importedNode, deep );
|
---|
5942 | break;
|
---|
5943 | case QDomNode::ProcessingInstructionNode:
|
---|
5944 | node = new QDomProcessingInstructionPrivate( (QDomProcessingInstructionPrivate*)importedNode, deep );
|
---|
5945 | break;
|
---|
5946 | case QDomNode::TextNode:
|
---|
5947 | node = new QDomTextPrivate( (QDomTextPrivate*)importedNode, deep );
|
---|
5948 | break;
|
---|
5949 | case QDomNode::CDATASectionNode:
|
---|
5950 | node = new QDomCDATASectionPrivate( (QDomCDATASectionPrivate*)importedNode, deep );
|
---|
5951 | break;
|
---|
5952 | case QDomNode::CommentNode:
|
---|
5953 | node = new QDomCommentPrivate( (QDomCommentPrivate*)importedNode, deep );
|
---|
5954 | break;
|
---|
5955 | default:
|
---|
5956 | break;
|
---|
5957 | }
|
---|
5958 | if ( node ) {
|
---|
5959 | node->setOwnerDocument( this );
|
---|
5960 | // The QDomNode constructor increases the refcount, so deref() first to
|
---|
5961 | // keep refcount balanced.
|
---|
5962 | node->deref();
|
---|
5963 | }
|
---|
5964 | return node;
|
---|
5965 | }
|
---|
5966 |
|
---|
5967 | void QDomDocumentPrivate::save( QTextStream& s, int, int indent ) const
|
---|
5968 | {
|
---|
5969 | bool doc = FALSE;
|
---|
5970 |
|
---|
5971 | QDomNodePrivate* n = first;
|
---|
5972 | if ( n && n->isProcessingInstruction() && n->nodeName()=="xml" ) {
|
---|
5973 | // we have an XML declaration
|
---|
5974 | QString data = n->nodeValue();
|
---|
5975 | QRegExp encoding( QString::fromLatin1("encoding\\s*=\\s*((\"([^\"]*)\")|('([^']*)'))") );
|
---|
5976 | encoding.search( data );
|
---|
5977 | QString enc = encoding.cap(3);
|
---|
5978 | if ( enc.isEmpty() ) {
|
---|
5979 | enc = encoding.cap(5);
|
---|
5980 | }
|
---|
5981 | if ( enc.isEmpty() ) {
|
---|
5982 | s.setEncoding( QTextStream::UnicodeUTF8 );
|
---|
5983 | } else {
|
---|
5984 | s.setCodec( QTextCodec::codecForName( enc ) );
|
---|
5985 | }
|
---|
5986 | } else {
|
---|
5987 | s.setEncoding( QTextStream::UnicodeUTF8 );
|
---|
5988 | }
|
---|
5989 | while ( n ) {
|
---|
5990 | if ( !doc && !(n->isProcessingInstruction()&&n->nodeName()=="xml") ) {
|
---|
5991 | // save doctype after XML declaration
|
---|
5992 | type->save( s, 0, indent );
|
---|
5993 | doc = TRUE;
|
---|
5994 | }
|
---|
5995 | n->save( s, 0, indent );
|
---|
5996 | n = n->next;
|
---|
5997 | }
|
---|
5998 | }
|
---|
5999 |
|
---|
6000 | /**************************************************************
|
---|
6001 | *
|
---|
6002 | * QDomDocument
|
---|
6003 | *
|
---|
6004 | **************************************************************/
|
---|
6005 |
|
---|
6006 | #define IMPL ((QDomDocumentPrivate*)impl)
|
---|
6007 |
|
---|
6008 | /*!
|
---|
6009 | \class QDomDocument qdom.h
|
---|
6010 | \reentrant
|
---|
6011 | \brief The QDomDocument class represents an XML document.
|
---|
6012 | \if defined(commercial)
|
---|
6013 | It is part of the <a href="commercialeditions.html">Qt Enterprise Edition</a>.
|
---|
6014 | \endif
|
---|
6015 |
|
---|
6016 | \module XML
|
---|
6017 | \ingroup xml-tools
|
---|
6018 |
|
---|
6019 | The QDomDocument class represents the entire XML document.
|
---|
6020 | Conceptually, it is the root of the document tree, and provides
|
---|
6021 | the primary access to the document's data.
|
---|
6022 |
|
---|
6023 | Since elements, text nodes, comments, processing instructions,
|
---|
6024 | etc., cannot exist outside the context of a document, the document
|
---|
6025 | class also contains the factory functions needed to create these
|
---|
6026 | objects. The node objects created have an ownerDocument() function
|
---|
6027 | which associates them with the document within whose context they
|
---|
6028 | were created. The DOM classes that will be used most often are
|
---|
6029 | QDomNode, QDomDocument, QDomElement and QDomText.
|
---|
6030 |
|
---|
6031 | The parsed XML is represented internally by a tree of objects that
|
---|
6032 | can be accessed using the various QDom classes. All QDom classes
|
---|
6033 | only \e reference objects in the internal tree. The internal
|
---|
6034 | objects in the DOM tree will get deleted once the last QDom
|
---|
6035 | object referencing them and the QDomDocument itself are deleted.
|
---|
6036 |
|
---|
6037 | Creation of elements, text nodes, etc. is done using the various
|
---|
6038 | factory functions provided in this class. Using the default
|
---|
6039 | constructors of the QDom classes will only result in empty
|
---|
6040 | objects that cannot be manipulated or inserted into the Document.
|
---|
6041 |
|
---|
6042 | The QDomDocument class has several functions for creating document
|
---|
6043 | data, for example, createElement(), createTextNode(),
|
---|
6044 | createComment(), createCDATASection(),
|
---|
6045 | createProcessingInstruction(), createAttribute() and
|
---|
6046 | createEntityReference(). Some of these functions have versions
|
---|
6047 | that support namespaces, i.e. createElementNS() and
|
---|
6048 | createAttributeNS(). The createDocumentFragment() function is used
|
---|
6049 | to hold parts of the document; this is useful for manipulating for
|
---|
6050 | complex documents.
|
---|
6051 |
|
---|
6052 | The entire content of the document is set with setContent(). This
|
---|
6053 | function parses the string it is passed as an XML document and
|
---|
6054 | creates the DOM tree that represents the document. The root
|
---|
6055 | element is available using documentElement(). The textual
|
---|
6056 | representation of the document can be obtained using toString().
|
---|
6057 |
|
---|
6058 | It is possible to insert a node from another document into the
|
---|
6059 | document using importNode().
|
---|
6060 |
|
---|
6061 | You can obtain a list of all the elements that have a particular
|
---|
6062 | tag with elementsByTagName() or with elementsByTagNameNS().
|
---|
6063 |
|
---|
6064 | The QDom classes are typically used as follows:
|
---|
6065 | \code
|
---|
6066 | QDomDocument doc( "mydocument" );
|
---|
6067 | QFile file( "mydocument.xml" );
|
---|
6068 | if ( !file.open( IO_ReadOnly ) )
|
---|
6069 | return;
|
---|
6070 | if ( !doc.setContent( &file ) ) {
|
---|
6071 | file.close();
|
---|
6072 | return;
|
---|
6073 | }
|
---|
6074 | file.close();
|
---|
6075 |
|
---|
6076 | // print out the element names of all elements that are direct children
|
---|
6077 | // of the outermost element.
|
---|
6078 | QDomElement docElem = doc.documentElement();
|
---|
6079 |
|
---|
6080 | QDomNode n = docElem.firstChild();
|
---|
6081 | while( !n.isNull() ) {
|
---|
6082 | QDomElement e = n.toElement(); // try to convert the node to an element.
|
---|
6083 | if( !e.isNull() ) {
|
---|
6084 | cout << e.tagName() << endl; // the node really is an element.
|
---|
6085 | }
|
---|
6086 | n = n.nextSibling();
|
---|
6087 | }
|
---|
6088 |
|
---|
6089 | // Here we append a new element to the end of the document
|
---|
6090 | QDomElement elem = doc.createElement( "img" );
|
---|
6091 | elem.setAttribute( "src", "myimage.png" );
|
---|
6092 | docElem.appendChild( elem );
|
---|
6093 | \endcode
|
---|
6094 |
|
---|
6095 | Once \c doc and \c elem go out of scope, the whole internal tree
|
---|
6096 | representing the XML document is deleted.
|
---|
6097 |
|
---|
6098 | To create a document using DOM use code like this:
|
---|
6099 | \code
|
---|
6100 | QDomDocument doc( "MyML" );
|
---|
6101 | QDomElement root = doc.createElement( "MyML" );
|
---|
6102 | doc.appendChild( root );
|
---|
6103 |
|
---|
6104 | QDomElement tag = doc.createElement( "Greeting" );
|
---|
6105 | root.appendChild( tag );
|
---|
6106 |
|
---|
6107 | QDomText t = doc.createTextNode( "Hello World" );
|
---|
6108 | tag.appendChild( t );
|
---|
6109 |
|
---|
6110 | QString xml = doc.toString();
|
---|
6111 | \endcode
|
---|
6112 |
|
---|
6113 | For further information about the Document Object Model see
|
---|
6114 | \link http://www.w3.org/TR/REC-DOM-Level-1/\endlink and
|
---|
6115 | \link http://www.w3.org/TR/DOM-Level-2-Core/\endlink.
|
---|
6116 | For a more general introduction of the DOM implementation see the
|
---|
6117 | QDomDocument documentation.
|
---|
6118 | */
|
---|
6119 |
|
---|
6120 |
|
---|
6121 | /*!
|
---|
6122 | Constructs an empty document.
|
---|
6123 | */
|
---|
6124 | QDomDocument::QDomDocument()
|
---|
6125 | {
|
---|
6126 | impl = new QDomDocumentPrivate;
|
---|
6127 | }
|
---|
6128 |
|
---|
6129 | /*!
|
---|
6130 | Creates a document and sets the name of the document type to \a
|
---|
6131 | name.
|
---|
6132 | */
|
---|
6133 | QDomDocument::QDomDocument( const QString& name )
|
---|
6134 | {
|
---|
6135 | // We take over ownership
|
---|
6136 | impl = new QDomDocumentPrivate( name );
|
---|
6137 | }
|
---|
6138 |
|
---|
6139 | /*!
|
---|
6140 | Creates a document with the document type \a doctype.
|
---|
6141 |
|
---|
6142 | \sa QDomImplementation::createDocumentType()
|
---|
6143 | */
|
---|
6144 | QDomDocument::QDomDocument( const QDomDocumentType& doctype )
|
---|
6145 | {
|
---|
6146 | impl = new QDomDocumentPrivate( (QDomDocumentTypePrivate*)(doctype.impl) );
|
---|
6147 | }
|
---|
6148 |
|
---|
6149 | /*!
|
---|
6150 | Constructs a copy of \a x.
|
---|
6151 |
|
---|
6152 | The data of the copy is shared (shallow copy): modifying one node
|
---|
6153 | will also change the other. If you want to make a deep copy, use
|
---|
6154 | cloneNode().
|
---|
6155 | */
|
---|
6156 | QDomDocument::QDomDocument( const QDomDocument& x )
|
---|
6157 | : QDomNode( x )
|
---|
6158 | {
|
---|
6159 | }
|
---|
6160 |
|
---|
6161 | QDomDocument::QDomDocument( QDomDocumentPrivate* x )
|
---|
6162 | : QDomNode( x )
|
---|
6163 | {
|
---|
6164 | }
|
---|
6165 |
|
---|
6166 | /*!
|
---|
6167 | Assigns \a x to this DOM document.
|
---|
6168 |
|
---|
6169 | The data of the copy is shared (shallow copy): modifying one node
|
---|
6170 | will also change the other. If you want to make a deep copy, use
|
---|
6171 | cloneNode().
|
---|
6172 | */
|
---|
6173 | QDomDocument& QDomDocument::operator= ( const QDomDocument& x )
|
---|
6174 | {
|
---|
6175 | return (QDomDocument&) QDomNode::operator=( x );
|
---|
6176 | }
|
---|
6177 |
|
---|
6178 | /*!
|
---|
6179 | Destroys the object and frees its resources.
|
---|
6180 | */
|
---|
6181 | QDomDocument::~QDomDocument()
|
---|
6182 | {
|
---|
6183 | }
|
---|
6184 |
|
---|
6185 | /*!
|
---|
6186 | \overload
|
---|
6187 |
|
---|
6188 | This function reads the XML document from the string \a text.
|
---|
6189 | Since \a text is already a Unicode string, no encoding detection
|
---|
6190 | is done.
|
---|
6191 | */
|
---|
6192 | bool QDomDocument::setContent( const QString& text, bool namespaceProcessing, QString *errorMsg, int *errorLine, int *errorColumn )
|
---|
6193 | {
|
---|
6194 | if ( !impl )
|
---|
6195 | impl = new QDomDocumentPrivate;
|
---|
6196 | QXmlInputSource source;
|
---|
6197 | source.setData( text );
|
---|
6198 | return IMPL->setContent( &source, namespaceProcessing, errorMsg, errorLine, errorColumn );
|
---|
6199 | }
|
---|
6200 |
|
---|
6201 | /*!
|
---|
6202 | This function parses the XML document from the byte array \a
|
---|
6203 | buffer and sets it as the content of the document. It tries to
|
---|
6204 | detect the encoding of the document as required by the XML
|
---|
6205 | specification.
|
---|
6206 |
|
---|
6207 | If \a namespaceProcessing is TRUE, the parser recognizes
|
---|
6208 | namespaces in the XML file and sets the prefix name, local name
|
---|
6209 | and namespace URI to appropriate values. If \a namespaceProcessing
|
---|
6210 | is FALSE, the parser does no namespace processing when it reads
|
---|
6211 | the XML file.
|
---|
6212 |
|
---|
6213 | If a parse error occurs, the function returns FALSE; otherwise it
|
---|
6214 | returns TRUE. If a parse error occurs and \a errorMsg, \a
|
---|
6215 | errorLine and \a errorColumn are not 0, the error message is
|
---|
6216 | placed in \a *errorMsg, the line number \a *errorLine and the
|
---|
6217 | column number in \a *errorColumn.
|
---|
6218 |
|
---|
6219 | If \a namespaceProcessing is TRUE, the function QDomNode::prefix()
|
---|
6220 | returns a string for all elements and attributes. It returns an
|
---|
6221 | empty string if the element or attribute has no prefix.
|
---|
6222 |
|
---|
6223 | If \a namespaceProcessing is FALSE, the functions
|
---|
6224 | QDomNode::prefix(), QDomNode::localName() and
|
---|
6225 | QDomNode::namespaceURI() return QString::null.
|
---|
6226 |
|
---|
6227 | \sa QDomNode::namespaceURI() QDomNode::localName()
|
---|
6228 | QDomNode::prefix() QString::isNull() QString::isEmpty()
|
---|
6229 | */
|
---|
6230 | bool QDomDocument::setContent( const QByteArray& buffer, bool namespaceProcessing, QString *errorMsg, int *errorLine, int *errorColumn )
|
---|
6231 | {
|
---|
6232 | if ( !impl )
|
---|
6233 | impl = new QDomDocumentPrivate;
|
---|
6234 | QBuffer buf( buffer );
|
---|
6235 | QXmlInputSource source( &buf );
|
---|
6236 | return IMPL->setContent( &source, namespaceProcessing, errorMsg, errorLine, errorColumn );
|
---|
6237 | }
|
---|
6238 |
|
---|
6239 | /*!
|
---|
6240 | \overload
|
---|
6241 |
|
---|
6242 | This function reads the XML document from the C string \a buffer.
|
---|
6243 |
|
---|
6244 | \warning This function does not try to detect the encoding:
|
---|
6245 | instead it assumes that the C string is UTF-8 encoded.
|
---|
6246 | */
|
---|
6247 | bool QDomDocument::setContent( const QCString& buffer, bool namespaceProcessing, QString *errorMsg, int *errorLine, int *errorColumn )
|
---|
6248 | {
|
---|
6249 | return setContent( QString::fromUtf8( buffer, buffer.length() ), namespaceProcessing, errorMsg, errorLine, errorColumn );
|
---|
6250 | }
|
---|
6251 |
|
---|
6252 | /*!
|
---|
6253 | \overload
|
---|
6254 |
|
---|
6255 | This function reads the XML document from the IO device \a dev.
|
---|
6256 | */
|
---|
6257 | bool QDomDocument::setContent( QIODevice* dev, bool namespaceProcessing, QString *errorMsg, int *errorLine, int *errorColumn )
|
---|
6258 | {
|
---|
6259 | if ( !impl )
|
---|
6260 | impl = new QDomDocumentPrivate;
|
---|
6261 | QXmlInputSource source( dev );
|
---|
6262 | return IMPL->setContent( &source, namespaceProcessing, errorMsg, errorLine, errorColumn );
|
---|
6263 | }
|
---|
6264 |
|
---|
6265 | /*!
|
---|
6266 | \overload
|
---|
6267 |
|
---|
6268 | This function reads the XML document from the string \a text.
|
---|
6269 | Since \a text is already a Unicode string, no encoding detection
|
---|
6270 | is performed.
|
---|
6271 |
|
---|
6272 | No namespace processing is performed either.
|
---|
6273 | */
|
---|
6274 | bool QDomDocument::setContent( const QString& text, QString *errorMsg, int *errorLine, int *errorColumn )
|
---|
6275 | {
|
---|
6276 | return setContent( text, FALSE, errorMsg, errorLine, errorColumn );
|
---|
6277 | }
|
---|
6278 |
|
---|
6279 | /*!
|
---|
6280 | \overload
|
---|
6281 |
|
---|
6282 | This function reads the XML document from the byte array \a
|
---|
6283 | buffer.
|
---|
6284 |
|
---|
6285 | No namespace processing is performed.
|
---|
6286 | */
|
---|
6287 | bool QDomDocument::setContent( const QByteArray& buffer, QString *errorMsg, int *errorLine, int *errorColumn )
|
---|
6288 | {
|
---|
6289 | return setContent( buffer, FALSE, errorMsg, errorLine, errorColumn );
|
---|
6290 | }
|
---|
6291 |
|
---|
6292 | /*!
|
---|
6293 | \overload
|
---|
6294 |
|
---|
6295 | This function reads the XML document from the C string \a buffer.
|
---|
6296 |
|
---|
6297 | No namespace processing is performed.
|
---|
6298 |
|
---|
6299 | \warning This function does not try to detect the encoding:
|
---|
6300 | instead it assumes that the C string is UTF-8 encoded.
|
---|
6301 | */
|
---|
6302 | bool QDomDocument::setContent( const QCString& buffer, QString *errorMsg, int *errorLine, int *errorColumn )
|
---|
6303 | {
|
---|
6304 | return setContent( buffer, FALSE, errorMsg, errorLine, errorColumn );
|
---|
6305 | }
|
---|
6306 |
|
---|
6307 | /*!
|
---|
6308 | \overload
|
---|
6309 |
|
---|
6310 | This function reads the XML document from the IO device \a dev.
|
---|
6311 |
|
---|
6312 | No namespace processing is performed.
|
---|
6313 | */
|
---|
6314 | bool QDomDocument::setContent( QIODevice* dev, QString *errorMsg, int *errorLine, int *errorColumn )
|
---|
6315 | {
|
---|
6316 | return setContent( dev, FALSE, errorMsg, errorLine, errorColumn );
|
---|
6317 | }
|
---|
6318 |
|
---|
6319 | /*!
|
---|
6320 | \overload
|
---|
6321 |
|
---|
6322 | This function reads the XML document from the QXmlInputSource \a source and
|
---|
6323 | parses it with the QXmlReader \a reader.
|
---|
6324 |
|
---|
6325 | This function doesn't change the features of the \a reader. If you want to
|
---|
6326 | use certain features for parsing you can use this function to set up the
|
---|
6327 | reader appropriate.
|
---|
6328 |
|
---|
6329 | \sa QXmlSimpleReader
|
---|
6330 | */
|
---|
6331 | bool QDomDocument::setContent( QXmlInputSource *source, QXmlReader *reader, QString *errorMsg, int *errorLine, int *errorColumn )
|
---|
6332 | {
|
---|
6333 | if ( !impl )
|
---|
6334 | impl = new QDomDocumentPrivate;
|
---|
6335 | return IMPL->setContent( source, reader, errorMsg, errorLine, errorColumn );
|
---|
6336 | }
|
---|
6337 |
|
---|
6338 | /*!
|
---|
6339 | Converts the parsed document back to its textual representation.
|
---|
6340 |
|
---|
6341 | \sa toCString()
|
---|
6342 | */
|
---|
6343 | QString QDomDocument::toString() const
|
---|
6344 | {
|
---|
6345 | QString str;
|
---|
6346 | QTextStream s( str, IO_WriteOnly );
|
---|
6347 | save( s, 1 );
|
---|
6348 |
|
---|
6349 | return str;
|
---|
6350 | }
|
---|
6351 |
|
---|
6352 | /*!
|
---|
6353 | \overload
|
---|
6354 |
|
---|
6355 | This function uses \a indent as the amount of space to indent
|
---|
6356 | subelements.
|
---|
6357 | */
|
---|
6358 | QString QDomDocument::toString( int indent ) const
|
---|
6359 | {
|
---|
6360 | QString str;
|
---|
6361 | QTextStream s( str, IO_WriteOnly );
|
---|
6362 | save( s, indent );
|
---|
6363 |
|
---|
6364 | return str;
|
---|
6365 | }
|
---|
6366 |
|
---|
6367 | /*!
|
---|
6368 | Converts the parsed document back to its textual representation
|
---|
6369 | and returns a QCString for that is encoded in UTF-8.
|
---|
6370 |
|
---|
6371 | \sa toString()
|
---|
6372 | */
|
---|
6373 | QCString QDomDocument::toCString() const
|
---|
6374 | {
|
---|
6375 | // ### if there is an encoding specified in the xml declaration, this
|
---|
6376 | // encoding declaration should be changed to utf8
|
---|
6377 | return toString().utf8();
|
---|
6378 | }
|
---|
6379 |
|
---|
6380 | /*!
|
---|
6381 | \overload
|
---|
6382 |
|
---|
6383 | This function uses \a indent as the amount of space to indent
|
---|
6384 | subelements.
|
---|
6385 | */
|
---|
6386 | QCString QDomDocument::toCString( int indent ) const
|
---|
6387 | {
|
---|
6388 | // ### if there is an encoding specified in the xml declaration, this
|
---|
6389 | // encoding declaration should be changed to utf8
|
---|
6390 | return toString( indent ).utf8();
|
---|
6391 | }
|
---|
6392 |
|
---|
6393 |
|
---|
6394 | /*!
|
---|
6395 | Returns the document type of this document.
|
---|
6396 | */
|
---|
6397 | QDomDocumentType QDomDocument::doctype() const
|
---|
6398 | {
|
---|
6399 | if ( !impl )
|
---|
6400 | return QDomDocumentType();
|
---|
6401 | return QDomDocumentType( IMPL->doctype() );
|
---|
6402 | }
|
---|
6403 |
|
---|
6404 | /*!
|
---|
6405 | Returns a QDomImplementation object.
|
---|
6406 | */
|
---|
6407 | QDomImplementation QDomDocument::implementation() const
|
---|
6408 | {
|
---|
6409 | if ( !impl )
|
---|
6410 | return QDomImplementation();
|
---|
6411 | return QDomImplementation( IMPL->implementation() );
|
---|
6412 | }
|
---|
6413 |
|
---|
6414 | /*!
|
---|
6415 | Returns the root element of the document.
|
---|
6416 | */
|
---|
6417 | QDomElement QDomDocument::documentElement() const
|
---|
6418 | {
|
---|
6419 | if ( !impl )
|
---|
6420 | return QDomElement();
|
---|
6421 | return QDomElement( IMPL->documentElement() );
|
---|
6422 | }
|
---|
6423 |
|
---|
6424 | /*!
|
---|
6425 | Creates a new element called \a tagName that can be inserted into
|
---|
6426 | the DOM tree, e.g. using QDomNode::appendChild().
|
---|
6427 |
|
---|
6428 | \sa createElementNS() QDomNode::appendChild() QDomNode::insertBefore()
|
---|
6429 | QDomNode::insertAfter()
|
---|
6430 | */
|
---|
6431 | QDomElement QDomDocument::createElement( const QString& tagName )
|
---|
6432 | {
|
---|
6433 | if ( !impl )
|
---|
6434 | return QDomElement();
|
---|
6435 | return QDomElement( IMPL->createElement( tagName ) );
|
---|
6436 | }
|
---|
6437 |
|
---|
6438 | /*!
|
---|
6439 | Creates a new document fragment, that can be used to hold parts of
|
---|
6440 | the document, e.g. when doing complex manipulations of the
|
---|
6441 | document tree.
|
---|
6442 | */
|
---|
6443 | QDomDocumentFragment QDomDocument::createDocumentFragment()
|
---|
6444 | {
|
---|
6445 | if ( !impl )
|
---|
6446 | return QDomDocumentFragment();
|
---|
6447 | return QDomDocumentFragment( IMPL->createDocumentFragment() );
|
---|
6448 | }
|
---|
6449 |
|
---|
6450 | /*!
|
---|
6451 | Creates a text node for the string \a value that can be inserted
|
---|
6452 | into the document tree, e.g. using QDomNode::appendChild().
|
---|
6453 |
|
---|
6454 | \sa QDomNode::appendChild() QDomNode::insertBefore() QDomNode::insertAfter()
|
---|
6455 | */
|
---|
6456 | QDomText QDomDocument::createTextNode( const QString& value )
|
---|
6457 | {
|
---|
6458 | if ( !impl )
|
---|
6459 | return QDomText();
|
---|
6460 | return QDomText( IMPL->createTextNode( value ) );
|
---|
6461 | }
|
---|
6462 |
|
---|
6463 | /*!
|
---|
6464 | Creates a new comment for the string \a value that can be inserted
|
---|
6465 | into the document, e.g. using QDomNode::appendChild().
|
---|
6466 |
|
---|
6467 | \sa QDomNode::appendChild() QDomNode::insertBefore() QDomNode::insertAfter()
|
---|
6468 | */
|
---|
6469 | QDomComment QDomDocument::createComment( const QString& value )
|
---|
6470 | {
|
---|
6471 | if ( !impl )
|
---|
6472 | return QDomComment();
|
---|
6473 | return QDomComment( IMPL->createComment( value ) );
|
---|
6474 | }
|
---|
6475 |
|
---|
6476 | /*!
|
---|
6477 | Creates a new CDATA section for the string \a value that can be
|
---|
6478 | inserted into the document, e.g. using QDomNode::appendChild().
|
---|
6479 |
|
---|
6480 | \sa QDomNode::appendChild() QDomNode::insertBefore() QDomNode::insertAfter()
|
---|
6481 | */
|
---|
6482 | QDomCDATASection QDomDocument::createCDATASection( const QString& value )
|
---|
6483 | {
|
---|
6484 | if ( !impl )
|
---|
6485 | return QDomCDATASection();
|
---|
6486 | return QDomCDATASection( IMPL->createCDATASection( value ) );
|
---|
6487 | }
|
---|
6488 |
|
---|
6489 | /*!
|
---|
6490 | Creates a new processing instruction that can be inserted into the
|
---|
6491 | document, e.g. using QDomNode::appendChild(). This function sets
|
---|
6492 | the target for the processing instruction to \a target and the
|
---|
6493 | data to \a data.
|
---|
6494 |
|
---|
6495 | \sa QDomNode::appendChild() QDomNode::insertBefore() QDomNode::insertAfter()
|
---|
6496 | */
|
---|
6497 | QDomProcessingInstruction QDomDocument::createProcessingInstruction( const QString& target,
|
---|
6498 | const QString& data )
|
---|
6499 | {
|
---|
6500 | if ( !impl )
|
---|
6501 | return QDomProcessingInstruction();
|
---|
6502 | return QDomProcessingInstruction( IMPL->createProcessingInstruction( target, data ) );
|
---|
6503 | }
|
---|
6504 |
|
---|
6505 |
|
---|
6506 | /*!
|
---|
6507 | Creates a new attribute called \a name that can be inserted into
|
---|
6508 | an element, e.g. using QDomElement::setAttributeNode().
|
---|
6509 |
|
---|
6510 | \sa createAttributeNS()
|
---|
6511 | */
|
---|
6512 | QDomAttr QDomDocument::createAttribute( const QString& name )
|
---|
6513 | {
|
---|
6514 | if ( !impl )
|
---|
6515 | return QDomAttr();
|
---|
6516 | return QDomAttr( IMPL->createAttribute( name ) );
|
---|
6517 | }
|
---|
6518 |
|
---|
6519 | /*!
|
---|
6520 | Creates a new entity reference called \a name that can be inserted
|
---|
6521 | into the document, e.g. using QDomNode::appendChild().
|
---|
6522 |
|
---|
6523 | \sa QDomNode::appendChild() QDomNode::insertBefore() QDomNode::insertAfter()
|
---|
6524 | */
|
---|
6525 | QDomEntityReference QDomDocument::createEntityReference( const QString& name )
|
---|
6526 | {
|
---|
6527 | if ( !impl )
|
---|
6528 | return QDomEntityReference();
|
---|
6529 | return QDomEntityReference( IMPL->createEntityReference( name ) );
|
---|
6530 | }
|
---|
6531 |
|
---|
6532 | /*!
|
---|
6533 | Returns a QDomNodeList, that contains all the elements in the
|
---|
6534 | document with the name \a tagname. The order of the node list is
|
---|
6535 | the order they are encountered in a preorder traversal of the
|
---|
6536 | element tree.
|
---|
6537 |
|
---|
6538 | \sa elementsByTagNameNS() QDomElement::elementsByTagName()
|
---|
6539 | */
|
---|
6540 | QDomNodeList QDomDocument::elementsByTagName( const QString& tagname ) const
|
---|
6541 | {
|
---|
6542 | return QDomNodeList( new QDomNodeListPrivate( impl, tagname ) );
|
---|
6543 | }
|
---|
6544 |
|
---|
6545 | /*!
|
---|
6546 | Imports the node \a importedNode from another document to this
|
---|
6547 | document. \a importedNode remains in the original document; this
|
---|
6548 | function creates a copy that can be used within this document.
|
---|
6549 |
|
---|
6550 | This function returns the imported node that belongs to this
|
---|
6551 | document. The returned node has no parent. It is not possible to
|
---|
6552 | import QDomDocument and QDomDocumentType nodes. In those cases
|
---|
6553 | this function returns a \link QDomNode::isNull() null node\endlink.
|
---|
6554 |
|
---|
6555 | If \a deep is TRUE, this function imports not only the node \a
|
---|
6556 | importedNode but its whole subtree; if it is FALSE, only the \a
|
---|
6557 | importedNode is imported. The argument \a deep has no effect on
|
---|
6558 | QDomAttr and QDomEntityReference nodes, since the descendents of
|
---|
6559 | QDomAttr nodes are always imported and those of
|
---|
6560 | QDomEntityReference nodes are never imported.
|
---|
6561 |
|
---|
6562 | The behavior of this function is slightly different depending on
|
---|
6563 | the node types:
|
---|
6564 | \table
|
---|
6565 | \header \i Node Type \i Behaviour
|
---|
6566 | \row \i QDomAttr
|
---|
6567 | \i The owner element is set to 0 and the specified flag is
|
---|
6568 | set to TRUE in the generated attribute. The whole subtree
|
---|
6569 | of \a importedNode is always imported for attribute nodes:
|
---|
6570 | \a deep has no effect.
|
---|
6571 | \row \i QDomDocument
|
---|
6572 | \i Document nodes cannot be imported.
|
---|
6573 | \row \i QDomDocumentFragment
|
---|
6574 | \i If \a deep is TRUE, this function imports the whole
|
---|
6575 | document fragment; otherwise it only generates an empty
|
---|
6576 | document fragment.
|
---|
6577 | \row \i QDomDocumentType
|
---|
6578 | \i Document type nodes cannot be imported.
|
---|
6579 | \row \i QDomElement
|
---|
6580 | \i Attributes for which QDomAttr::specified() is TRUE are
|
---|
6581 | also imported, other attributes are not imported. If \a
|
---|
6582 | deep is TRUE, this function also imports the subtree of \a
|
---|
6583 | importedNode; otherwise it imports only the element node
|
---|
6584 | (and some attributes, see above).
|
---|
6585 | \row \i QDomEntity
|
---|
6586 | \i Entity nodes can be imported, but at the moment there is
|
---|
6587 | no way to use them since the document type is read-only in
|
---|
6588 | DOM level 2.
|
---|
6589 | \row \i QDomEntityReference
|
---|
6590 | \i Descendents of entity reference nodes are never imported:
|
---|
6591 | \a deep has no effect.
|
---|
6592 | \row \i QDomNotation
|
---|
6593 | \i Notation nodes can be imported, but at the moment there is
|
---|
6594 | no way to use them since the document type is read-only in
|
---|
6595 | DOM level 2.
|
---|
6596 | \row \i QDomProcessingInstruction
|
---|
6597 | \i The target and value of the processing instruction is
|
---|
6598 | copied to the new node.
|
---|
6599 | \row \i QDomText
|
---|
6600 | \i The text is copied to the new node.
|
---|
6601 | \row \i QDomCDATASection
|
---|
6602 | \i The text is copied to the new node.
|
---|
6603 | \row \i QDomComment
|
---|
6604 | \i The text is copied to the new node.
|
---|
6605 | \endtable
|
---|
6606 |
|
---|
6607 | \sa QDomElement::setAttribute() QDomNode::insertBefore()
|
---|
6608 | QDomNode::insertAfter() QDomNode::replaceChild() QDomNode::removeChild()
|
---|
6609 | QDomNode::appendChild()
|
---|
6610 | */
|
---|
6611 | QDomNode QDomDocument::importNode( const QDomNode& importedNode, bool deep )
|
---|
6612 | {
|
---|
6613 | if ( !impl )
|
---|
6614 | return QDomNode();
|
---|
6615 | return QDomNode( IMPL->importNode( importedNode.impl, deep ) );
|
---|
6616 | }
|
---|
6617 |
|
---|
6618 | /*!
|
---|
6619 | Creates a new element with namespace support that can be inserted
|
---|
6620 | into the DOM tree. The name of the element is \a qName and the
|
---|
6621 | namespace URI is \a nsURI. This function also sets
|
---|
6622 | QDomNode::prefix() and QDomNode::localName() to appropriate values
|
---|
6623 | (depending on \a qName).
|
---|
6624 |
|
---|
6625 | \sa createElement()
|
---|
6626 | */
|
---|
6627 | QDomElement QDomDocument::createElementNS( const QString& nsURI, const QString& qName )
|
---|
6628 | {
|
---|
6629 | if ( !impl )
|
---|
6630 | return QDomElement();
|
---|
6631 | return QDomElement( IMPL->createElementNS( nsURI, qName ) );
|
---|
6632 | }
|
---|
6633 |
|
---|
6634 | /*!
|
---|
6635 | Creates a new attribute with namespace support that can be
|
---|
6636 | inserted into an element. The name of the attribute is \a qName
|
---|
6637 | and the namespace URI is \a nsURI. This function also sets
|
---|
6638 | QDomNode::prefix() and QDomNode::localName() to appropriate values
|
---|
6639 | (depending on \a qName).
|
---|
6640 |
|
---|
6641 | \sa createAttribute()
|
---|
6642 | */
|
---|
6643 | QDomAttr QDomDocument::createAttributeNS( const QString& nsURI, const QString& qName )
|
---|
6644 | {
|
---|
6645 | if ( !impl )
|
---|
6646 | return QDomAttr();
|
---|
6647 | return QDomAttr( IMPL->createAttributeNS( nsURI, qName ) );
|
---|
6648 | }
|
---|
6649 |
|
---|
6650 | /*!
|
---|
6651 | Returns a QDomNodeList that contains all the elements in the
|
---|
6652 | document with the local name \a localName and a namespace URI of
|
---|
6653 | \a nsURI. The order of the node list is the order they are
|
---|
6654 | encountered in a preorder traversal of the element tree.
|
---|
6655 |
|
---|
6656 | \sa elementsByTagName() QDomElement::elementsByTagNameNS()
|
---|
6657 | */
|
---|
6658 | QDomNodeList QDomDocument::elementsByTagNameNS( const QString& nsURI, const QString& localName )
|
---|
6659 | {
|
---|
6660 | return QDomNodeList( new QDomNodeListPrivate( impl, nsURI, localName ) );
|
---|
6661 | }
|
---|
6662 |
|
---|
6663 | /*!
|
---|
6664 | Returns the element whose ID is equal to \a elementId. If no
|
---|
6665 | element with the ID was found, this function returns a \link
|
---|
6666 | QDomNode::isNull() null element\endlink.
|
---|
6667 |
|
---|
6668 | Since the QDomClasses do not know which attributes are element
|
---|
6669 | IDs, this function returns always a \link QDomNode::isNull() null
|
---|
6670 | element\endlink. This may change in a future version.
|
---|
6671 | */
|
---|
6672 | QDomElement QDomDocument::elementById( const QString& /*elementId*/ )
|
---|
6673 | {
|
---|
6674 | return QDomElement();
|
---|
6675 | }
|
---|
6676 |
|
---|
6677 | /*!
|
---|
6678 | Returns \c DocumentNode.
|
---|
6679 | */
|
---|
6680 | QDomNode::NodeType QDomDocument::nodeType() const
|
---|
6681 | {
|
---|
6682 | return DocumentNode;
|
---|
6683 | }
|
---|
6684 |
|
---|
6685 | /*!
|
---|
6686 | Returns TRUE.
|
---|
6687 | */
|
---|
6688 | bool QDomDocument::isDocument() const
|
---|
6689 | {
|
---|
6690 | return TRUE;
|
---|
6691 | }
|
---|
6692 |
|
---|
6693 |
|
---|
6694 | #undef IMPL
|
---|
6695 |
|
---|
6696 | /**************************************************************
|
---|
6697 | *
|
---|
6698 | * Node casting functions
|
---|
6699 | *
|
---|
6700 | **************************************************************/
|
---|
6701 |
|
---|
6702 | /*!
|
---|
6703 | Converts a QDomNode into a QDomAttr. If the node is not an
|
---|
6704 | attribute, the returned object will be \link QDomNode::isNull()
|
---|
6705 | null\endlink.
|
---|
6706 |
|
---|
6707 | \sa isAttr()
|
---|
6708 | */
|
---|
6709 | QDomAttr QDomNode::toAttr()
|
---|
6710 | {
|
---|
6711 | if ( impl && impl->isAttr() )
|
---|
6712 | return QDomAttr( ((QDomAttrPrivate*)impl) );
|
---|
6713 | return QDomAttr();
|
---|
6714 | }
|
---|
6715 |
|
---|
6716 | /*!
|
---|
6717 | Converts a QDomNode into a QDomCDATASection. If the node is not a
|
---|
6718 | CDATA section, the returned object will be \link
|
---|
6719 | QDomNode::isNull() null\endlink.
|
---|
6720 |
|
---|
6721 | \sa isCDATASection()
|
---|
6722 | */
|
---|
6723 | QDomCDATASection QDomNode::toCDATASection()
|
---|
6724 | {
|
---|
6725 | if ( impl && impl->isCDATASection() )
|
---|
6726 | return QDomCDATASection( ((QDomCDATASectionPrivate*)impl) );
|
---|
6727 | return QDomCDATASection();
|
---|
6728 | }
|
---|
6729 |
|
---|
6730 | /*!
|
---|
6731 | Converts a QDomNode into a QDomDocumentFragment. If the node is
|
---|
6732 | not a document fragment the returned object will be \link
|
---|
6733 | QDomNode::isNull() null\endlink.
|
---|
6734 |
|
---|
6735 | \sa isDocumentFragment()
|
---|
6736 | */
|
---|
6737 | QDomDocumentFragment QDomNode::toDocumentFragment()
|
---|
6738 | {
|
---|
6739 | if ( impl && impl->isDocumentFragment() )
|
---|
6740 | return QDomDocumentFragment( ((QDomDocumentFragmentPrivate*)impl) );
|
---|
6741 | return QDomDocumentFragment();
|
---|
6742 | }
|
---|
6743 |
|
---|
6744 | /*!
|
---|
6745 | Converts a QDomNode into a QDomDocument. If the node is not a
|
---|
6746 | document the returned object will be \link QDomNode::isNull()
|
---|
6747 | null\endlink.
|
---|
6748 |
|
---|
6749 | \sa isDocument()
|
---|
6750 | */
|
---|
6751 | QDomDocument QDomNode::toDocument()
|
---|
6752 | {
|
---|
6753 | if ( impl && impl->isDocument() )
|
---|
6754 | return QDomDocument( ((QDomDocumentPrivate*)impl) );
|
---|
6755 | return QDomDocument();
|
---|
6756 | }
|
---|
6757 |
|
---|
6758 | /*!
|
---|
6759 | Converts a QDomNode into a QDomDocumentType. If the node is not a
|
---|
6760 | document type the returned object will be \link QDomNode::isNull()
|
---|
6761 | null\endlink.
|
---|
6762 |
|
---|
6763 | \sa isDocumentType()
|
---|
6764 | */
|
---|
6765 | QDomDocumentType QDomNode::toDocumentType()
|
---|
6766 | {
|
---|
6767 | if ( impl && impl->isDocumentType() )
|
---|
6768 | return QDomDocumentType( ((QDomDocumentTypePrivate*)impl) );
|
---|
6769 | return QDomDocumentType();
|
---|
6770 | }
|
---|
6771 |
|
---|
6772 | /*!
|
---|
6773 | Converts a QDomNode into a QDomElement. If the node is not an
|
---|
6774 | element the returned object will be \link QDomNode::isNull()
|
---|
6775 | null\endlink.
|
---|
6776 |
|
---|
6777 | \sa isElement()
|
---|
6778 | */
|
---|
6779 | QDomElement QDomNode::toElement()
|
---|
6780 | {
|
---|
6781 | if ( impl && impl->isElement() )
|
---|
6782 | return QDomElement( ((QDomElementPrivate*)impl) );
|
---|
6783 | return QDomElement();
|
---|
6784 | }
|
---|
6785 |
|
---|
6786 | /*!
|
---|
6787 | Converts a QDomNode into a QDomEntityReference. If the node is not
|
---|
6788 | an entity reference, the returned object will be \link
|
---|
6789 | QDomNode::isNull() null\endlink.
|
---|
6790 |
|
---|
6791 | \sa isEntityReference()
|
---|
6792 | */
|
---|
6793 | QDomEntityReference QDomNode::toEntityReference()
|
---|
6794 | {
|
---|
6795 | if ( impl && impl->isEntityReference() )
|
---|
6796 | return QDomEntityReference( ((QDomEntityReferencePrivate*)impl) );
|
---|
6797 | return QDomEntityReference();
|
---|
6798 | }
|
---|
6799 |
|
---|
6800 | /*!
|
---|
6801 | Converts a QDomNode into a QDomText. If the node is not a text,
|
---|
6802 | the returned object will be \link QDomNode::isNull() null\endlink.
|
---|
6803 |
|
---|
6804 | \sa isText()
|
---|
6805 | */
|
---|
6806 | QDomText QDomNode::toText()
|
---|
6807 | {
|
---|
6808 | if ( impl && impl->isText() )
|
---|
6809 | return QDomText( ((QDomTextPrivate*)impl) );
|
---|
6810 | return QDomText();
|
---|
6811 | }
|
---|
6812 |
|
---|
6813 | /*!
|
---|
6814 | Converts a QDomNode into a QDomEntity. If the node is not an
|
---|
6815 | entity the returned object will be \link QDomNode::isNull()
|
---|
6816 | null\endlink.
|
---|
6817 |
|
---|
6818 | \sa isEntity()
|
---|
6819 | */
|
---|
6820 | QDomEntity QDomNode::toEntity()
|
---|
6821 | {
|
---|
6822 | if ( impl && impl->isEntity() )
|
---|
6823 | return QDomEntity( ((QDomEntityPrivate*)impl) );
|
---|
6824 | return QDomEntity();
|
---|
6825 | }
|
---|
6826 |
|
---|
6827 | /*!
|
---|
6828 | Converts a QDomNode into a QDomNotation. If the node is not a
|
---|
6829 | notation the returned object will be \link QDomNode::isNull()
|
---|
6830 | null\endlink.
|
---|
6831 |
|
---|
6832 | \sa isNotation()
|
---|
6833 | */
|
---|
6834 | QDomNotation QDomNode::toNotation()
|
---|
6835 | {
|
---|
6836 | if ( impl && impl->isNotation() )
|
---|
6837 | return QDomNotation( ((QDomNotationPrivate*)impl) );
|
---|
6838 | return QDomNotation();
|
---|
6839 | }
|
---|
6840 |
|
---|
6841 | /*!
|
---|
6842 | Converts a QDomNode into a QDomProcessingInstruction. If the node
|
---|
6843 | is not a processing instruction the returned object will be \link
|
---|
6844 | QDomNode::isNull() null\endlink.
|
---|
6845 |
|
---|
6846 | \sa isProcessingInstruction()
|
---|
6847 | */
|
---|
6848 | QDomProcessingInstruction QDomNode::toProcessingInstruction()
|
---|
6849 | {
|
---|
6850 | if ( impl && impl->isProcessingInstruction() )
|
---|
6851 | return QDomProcessingInstruction( ((QDomProcessingInstructionPrivate*)impl) );
|
---|
6852 | return QDomProcessingInstruction();
|
---|
6853 | }
|
---|
6854 |
|
---|
6855 | /*!
|
---|
6856 | Converts a QDomNode into a QDomCharacterData. If the node is not a
|
---|
6857 | character data node the returned object will be \link
|
---|
6858 | QDomNode::isNull() null\endlink.
|
---|
6859 |
|
---|
6860 | \sa isCharacterData()
|
---|
6861 | */
|
---|
6862 | QDomCharacterData QDomNode::toCharacterData()
|
---|
6863 | {
|
---|
6864 | if ( impl && impl->isCharacterData() )
|
---|
6865 | return QDomCharacterData( ((QDomCharacterDataPrivate*)impl) );
|
---|
6866 | return QDomCharacterData();
|
---|
6867 | }
|
---|
6868 |
|
---|
6869 | /*!
|
---|
6870 | Converts a QDomNode into a QDomComment. If the node is not a
|
---|
6871 | comment the returned object will be \link QDomNode::isNull()
|
---|
6872 | null\endlink.
|
---|
6873 |
|
---|
6874 | \sa isComment()
|
---|
6875 | */
|
---|
6876 | QDomComment QDomNode::toComment()
|
---|
6877 | {
|
---|
6878 | if ( impl && impl->isComment() )
|
---|
6879 | return QDomComment( ((QDomCommentPrivate*)impl) );
|
---|
6880 | return QDomComment();
|
---|
6881 | }
|
---|
6882 |
|
---|
6883 | /**************************************************************
|
---|
6884 | *
|
---|
6885 | * QDomHandler
|
---|
6886 | *
|
---|
6887 | **************************************************************/
|
---|
6888 |
|
---|
6889 | QDomHandler::QDomHandler( QDomDocumentPrivate* adoc, bool namespaceProcessing )
|
---|
6890 | {
|
---|
6891 | doc = adoc;
|
---|
6892 | node = doc;
|
---|
6893 | cdata = FALSE;
|
---|
6894 | nsProcessing = namespaceProcessing;
|
---|
6895 | }
|
---|
6896 |
|
---|
6897 | QDomHandler::~QDomHandler()
|
---|
6898 | {
|
---|
6899 | }
|
---|
6900 |
|
---|
6901 | bool QDomHandler::endDocument()
|
---|
6902 | {
|
---|
6903 | // ### is this really necessary? (rms)
|
---|
6904 | if ( node != doc )
|
---|
6905 | return FALSE;
|
---|
6906 | return TRUE;
|
---|
6907 | }
|
---|
6908 |
|
---|
6909 | bool QDomHandler::startDTD( const QString& name, const QString& publicId, const QString& systemId )
|
---|
6910 | {
|
---|
6911 | doc->doctype()->name = name;
|
---|
6912 | doc->doctype()->publicId = publicId;
|
---|
6913 | doc->doctype()->systemId = systemId;
|
---|
6914 | return TRUE;
|
---|
6915 | }
|
---|
6916 |
|
---|
6917 | bool QDomHandler::startElement( const QString& nsURI, const QString&, const QString& qName, const QXmlAttributes& atts )
|
---|
6918 | {
|
---|
6919 | // tag name
|
---|
6920 | QDomNodePrivate* n;
|
---|
6921 | if ( nsProcessing ) {
|
---|
6922 | n = doc->createElementNS( nsURI, qName );
|
---|
6923 | } else {
|
---|
6924 | n = doc->createElement( qName );
|
---|
6925 | }
|
---|
6926 | node->appendChild( n );
|
---|
6927 | node = n;
|
---|
6928 |
|
---|
6929 | // attributes
|
---|
6930 | for ( int i=0; i<atts.length(); i++ )
|
---|
6931 | {
|
---|
6932 | if ( nsProcessing ) {
|
---|
6933 | ((QDomElementPrivate*)node)->setAttributeNS( atts.uri(i), atts.qName(i), atts.value(i) );
|
---|
6934 | } else {
|
---|
6935 | ((QDomElementPrivate*)node)->setAttribute( atts.qName(i), atts.value(i) );
|
---|
6936 | }
|
---|
6937 | }
|
---|
6938 |
|
---|
6939 | return TRUE;
|
---|
6940 | }
|
---|
6941 |
|
---|
6942 | bool QDomHandler::endElement( const QString&, const QString&, const QString& )
|
---|
6943 | {
|
---|
6944 | if ( node == doc )
|
---|
6945 | return FALSE;
|
---|
6946 | node = node->parent();
|
---|
6947 |
|
---|
6948 | return TRUE;
|
---|
6949 | }
|
---|
6950 |
|
---|
6951 | bool QDomHandler::characters( const QString& ch )
|
---|
6952 | {
|
---|
6953 | // No text as child of some document
|
---|
6954 | if ( node == doc )
|
---|
6955 | return FALSE;
|
---|
6956 |
|
---|
6957 | if ( cdata ) {
|
---|
6958 | node->appendChild( doc->createCDATASection( ch ) );
|
---|
6959 | } else if ( !entityName.isEmpty() ) {
|
---|
6960 | QDomEntityPrivate* e = new QDomEntityPrivate( doc, 0, entityName,
|
---|
6961 | QString::null, QString::null, QString::null );
|
---|
6962 | e->value = ch;
|
---|
6963 | doc->doctype()->appendChild( e );
|
---|
6964 | node->appendChild( doc->createEntityReference( entityName ) );
|
---|
6965 | } else {
|
---|
6966 | node->appendChild( doc->createTextNode( ch ) );
|
---|
6967 | }
|
---|
6968 |
|
---|
6969 | return TRUE;
|
---|
6970 | }
|
---|
6971 |
|
---|
6972 | bool QDomHandler::processingInstruction( const QString& target, const QString& data )
|
---|
6973 | {
|
---|
6974 | node->appendChild( doc->createProcessingInstruction( target, data ) );
|
---|
6975 | return TRUE;
|
---|
6976 | }
|
---|
6977 |
|
---|
6978 | bool QDomHandler::skippedEntity( const QString& name )
|
---|
6979 | {
|
---|
6980 | node->appendChild( doc->createEntityReference( name ) );
|
---|
6981 | return TRUE;
|
---|
6982 | }
|
---|
6983 |
|
---|
6984 | bool QDomHandler::fatalError( const QXmlParseException& exception )
|
---|
6985 | {
|
---|
6986 | errorMsg = exception.message();
|
---|
6987 | errorLine = exception.lineNumber();
|
---|
6988 | errorColumn = exception.columnNumber();
|
---|
6989 | return QXmlDefaultHandler::fatalError( exception );
|
---|
6990 | }
|
---|
6991 |
|
---|
6992 | bool QDomHandler::startCDATA()
|
---|
6993 | {
|
---|
6994 | cdata = TRUE;
|
---|
6995 | return TRUE;
|
---|
6996 | }
|
---|
6997 |
|
---|
6998 | bool QDomHandler::endCDATA()
|
---|
6999 | {
|
---|
7000 | cdata = FALSE;
|
---|
7001 | return TRUE;
|
---|
7002 | }
|
---|
7003 |
|
---|
7004 | bool QDomHandler::startEntity( const QString &name )
|
---|
7005 | {
|
---|
7006 | entityName = name;
|
---|
7007 | return TRUE;
|
---|
7008 | }
|
---|
7009 |
|
---|
7010 | bool QDomHandler::endEntity( const QString & )
|
---|
7011 | {
|
---|
7012 | entityName = QString::null;
|
---|
7013 | return TRUE;
|
---|
7014 | }
|
---|
7015 |
|
---|
7016 | bool QDomHandler::comment( const QString& ch )
|
---|
7017 | {
|
---|
7018 | node->appendChild( doc->createComment( ch ) );
|
---|
7019 | return TRUE;
|
---|
7020 | }
|
---|
7021 |
|
---|
7022 | bool QDomHandler::unparsedEntityDecl( const QString &name, const QString &publicId, const QString &systemId, const QString ¬ationName )
|
---|
7023 | {
|
---|
7024 | QDomEntityPrivate* e = new QDomEntityPrivate( doc, 0, name,
|
---|
7025 | publicId, systemId, notationName );
|
---|
7026 | doc->doctype()->appendChild( e );
|
---|
7027 | return TRUE;
|
---|
7028 | }
|
---|
7029 |
|
---|
7030 | bool QDomHandler::externalEntityDecl( const QString &name, const QString &publicId, const QString &systemId )
|
---|
7031 | {
|
---|
7032 | return unparsedEntityDecl( name, publicId, systemId, QString::null );
|
---|
7033 | }
|
---|
7034 |
|
---|
7035 | bool QDomHandler::notationDecl( const QString & name, const QString & publicId, const QString & systemId )
|
---|
7036 | {
|
---|
7037 | QDomNotationPrivate* n = new QDomNotationPrivate( doc, 0, name, publicId, systemId );
|
---|
7038 | doc->doctype()->appendChild( n );
|
---|
7039 | return TRUE;
|
---|
7040 | }
|
---|
7041 |
|
---|
7042 | } // namespace PsiXml
|
---|
7043 |
|
---|
7044 | #endif //QT_NO_DOM
|
---|