1
/****************************************************************************
2
** $Id: qdom.cpp,v 1.1 2004/02/29 00:05:06 justin Exp $
4
** Implementation of QDomDocument and related classes.
8
** Copyright (C) 1992-2002 Trolltech AS. All rights reserved.
10
** This file is part of the xml module of the Qt GUI Toolkit.
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.
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.
21
** Licensees holding valid Qt Enterprise Edition licenses may use this
22
** file in accordance with the Qt Commercial License Agreement provided
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.
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.
33
** Contact info@trolltech.com if any conditions of this licensing are
36
**********************************************************************/
45
#include "qtextstream.h"
46
#include "qtextcodec.h"
47
#include "qiodevice.h"
54
### old todo comments -- I don't know if they still apply...
56
If the document dies, remove all pointers to it from children
57
which can not be deleted at this time.
59
If a node dies and has direct children which can not be deleted,
60
then remove the pointer to the parent.
62
createElement and friends create double reference counts.
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
80
Helper to split a qualified name in the prefix and local name.
82
static void qt_split_namespace( QString& prefix, QString& name, const QString& qName, bool hasURI )
84
int i = qName.find( ':' );
89
prefix = QString::null;
92
prefix = qName.left( i );
93
name = qName.mid( i + 1 );
98
Counter for the QDomNodeListPrivate timestamps.
100
static volatile long qt_nodeListTime = 0;
102
/**************************************************************
104
* Private class declerations
106
**************************************************************/
108
class QDomImplementationPrivate : public QShared
111
QDomImplementationPrivate();
112
~QDomImplementationPrivate();
114
QDomImplementationPrivate* clone();
118
class QDomNodePrivate : public QShared
121
QDomNodePrivate( QDomDocumentPrivate*, QDomNodePrivate* parent = 0 );
122
QDomNodePrivate( QDomNodePrivate* n, bool deep );
123
virtual ~QDomNodePrivate();
125
QString nodeName() const { return name; }
126
QString nodeValue() const { return value; }
127
virtual void setNodeValue( const QString& v ) { value = v; }
129
QDomDocumentPrivate* ownerDocument();
130
void setOwnerDocument( QDomDocumentPrivate* doc );
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 );
140
QDomNodePrivate* namedItem( const QString& name );
142
virtual QDomNodePrivate* cloneNode( bool deep = TRUE );
143
virtual void normalize();
144
virtual void clear();
146
QDomNodePrivate* parent() { return hasParent ? ownerNode : 0; }
147
void setParent( QDomNodePrivate *p ) { ownerNode = p; hasParent = TRUE; }
149
ownerNode = hasParent ? (QDomNodePrivate*)ownerDocument() : 0;
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; }
169
virtual void save( QTextStream&, int, int ) const;
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;
178
QString name; // this is the local name if prefix != null
180
QString prefix; // set this only for ElementNode and AttributeNode
181
QString namespaceURI; // set this only for ElementNode and AttributeNode
182
bool createdWithDom1Interface;
186
class QDomNodeListPrivate : public QShared
189
QDomNodeListPrivate( QDomNodePrivate* );
190
QDomNodeListPrivate( QDomNodePrivate*, const QString& );
191
QDomNodeListPrivate( QDomNodePrivate*, const QString&, const QString& );
192
virtual ~QDomNodeListPrivate();
194
virtual bool operator== ( const QDomNodeListPrivate& ) const;
195
virtual bool operator!= ( const QDomNodeListPrivate& ) const;
198
virtual QDomNodePrivate* item( int index );
199
virtual uint length() const;
201
QDomNodePrivate* node_impl;
204
QPtrList<QDomNodePrivate> list;
208
class QDomNamedNodeMapPrivate : public QShared
211
QDomNamedNodeMapPrivate( QDomNodePrivate* );
212
~QDomNamedNodeMapPrivate();
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;
221
bool contains( const QString& name ) const;
222
bool containsNS( const QString& nsURI, const QString & localName ) const;
225
* Remove all children from the map.
228
bool isReadOnly() { return readonly; }
229
void setReadOnly( bool r ) { readonly = r; }
230
bool isAppendToParent() { return appendToParent; }
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.
237
* By default this value is FALSE and the map will handle reference counting
240
void setAppendToParent( bool b ) { appendToParent = b; }
243
* Creates a copy of the map. It is a deep copy
244
* that means that all children are cloned.
246
QDomNamedNodeMapPrivate* clone( QDomNodePrivate* parent );
249
QDict<QDomNodePrivate> map;
250
QDomNodePrivate* parent;
255
class QDomDocumentTypePrivate : public QDomNodePrivate
258
QDomDocumentTypePrivate( QDomDocumentPrivate*, QDomNodePrivate* parent = 0 );
259
QDomDocumentTypePrivate( QDomDocumentTypePrivate* n, bool deep );
260
~QDomDocumentTypePrivate();
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 );
271
bool isDocumentType() { return TRUE; }
272
QDomNode::NodeType nodeType() const { return QDomNode::DocumentTypeNode; }
274
void save( QTextStream& s, int, int ) const;
277
QDomNamedNodeMapPrivate* entities;
278
QDomNamedNodeMapPrivate* notations;
281
QString internalSubset;
284
class QDomDocumentFragmentPrivate : public QDomNodePrivate
287
QDomDocumentFragmentPrivate( QDomDocumentPrivate*, QDomNodePrivate* parent = 0 );
288
QDomDocumentFragmentPrivate( QDomNodePrivate* n, bool deep );
289
~QDomDocumentFragmentPrivate();
291
// Reimplemented from QDomNodePrivate
292
QDomNodePrivate* cloneNode( bool deep = TRUE );
293
bool isDocumentFragment() { return TRUE; }
294
QDomNode::NodeType nodeType() const { return QDomNode::DocumentFragmentNode; }
297
class QDomCharacterDataPrivate : public QDomNodePrivate
300
QDomCharacterDataPrivate( QDomDocumentPrivate*, QDomNodePrivate* parent, const QString& data );
301
QDomCharacterDataPrivate( QDomCharacterDataPrivate* n, bool deep );
302
~QDomCharacterDataPrivate();
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 );
311
// Reimplemented from QDomNodePrivate
312
bool isCharacterData() { return TRUE; }
313
QDomNode::NodeType nodeType() const { return QDomNode::CharacterDataNode; }
314
QDomNodePrivate* cloneNode( bool deep = TRUE );
318
class QDomTextPrivate : public QDomCharacterDataPrivate
321
QDomTextPrivate( QDomDocumentPrivate*, QDomNodePrivate* parent, const QString& value );
322
QDomTextPrivate( QDomTextPrivate* n, bool deep );
325
QDomTextPrivate* splitText( int offset );
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;
335
class QDomAttrPrivate : public QDomNodePrivate
338
QDomAttrPrivate( QDomDocumentPrivate*, QDomNodePrivate*, const QString& name );
339
QDomAttrPrivate( QDomDocumentPrivate*, QDomNodePrivate*, const QString& nsURI, const QString& qName );
340
QDomAttrPrivate( QDomAttrPrivate* n, bool deep );
343
bool specified() const;
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;
356
class QDomElementPrivate : public QDomNodePrivate
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();
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 );
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;
388
QDomNamedNodeMapPrivate* m_attr;
392
class QDomCommentPrivate : public QDomCharacterDataPrivate
395
QDomCommentPrivate( QDomDocumentPrivate*, QDomNodePrivate* parent, const QString& value );
396
QDomCommentPrivate( QDomCommentPrivate* n, bool deep );
397
~QDomCommentPrivate();
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;
407
class QDomCDATASectionPrivate : public QDomTextPrivate
410
QDomCDATASectionPrivate( QDomDocumentPrivate*, QDomNodePrivate* parent, const QString& value );
411
QDomCDATASectionPrivate( QDomCDATASectionPrivate* n, bool deep );
412
~QDomCDATASectionPrivate();
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;
422
class QDomNotationPrivate : public QDomNodePrivate
425
QDomNotationPrivate( QDomDocumentPrivate*, QDomNodePrivate* parent, const QString& name,
426
const QString& pub, const QString& sys );
427
QDomNotationPrivate( QDomNotationPrivate* n, bool deep );
428
~QDomNotationPrivate();
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;
441
class QDomEntityPrivate : public QDomNodePrivate
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();
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;
458
QString m_notationName;
461
class QDomEntityReferencePrivate : public QDomNodePrivate
464
QDomEntityReferencePrivate( QDomDocumentPrivate*, QDomNodePrivate* parent, const QString& name );
465
QDomEntityReferencePrivate( QDomNodePrivate* n, bool deep );
466
~QDomEntityReferencePrivate();
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;
475
class QDomProcessingInstructionPrivate : public QDomNodePrivate
478
QDomProcessingInstructionPrivate( QDomDocumentPrivate*, QDomNodePrivate* parent, const QString& target,
479
const QString& data);
480
QDomProcessingInstructionPrivate( QDomProcessingInstructionPrivate* n, bool deep );
481
~QDomProcessingInstructionPrivate();
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;
490
class QDomDocumentPrivate : public QDomNodePrivate
493
QDomDocumentPrivate();
494
QDomDocumentPrivate( const QString& name );
495
QDomDocumentPrivate( QDomDocumentTypePrivate* dt );
496
QDomDocumentPrivate( QDomDocumentPrivate* n, bool deep );
497
~QDomDocumentPrivate();
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 );
503
QDomDocumentTypePrivate* doctype() { return type; };
504
QDomImplementationPrivate* implementation() { return impl; };
505
QDomElementPrivate* documentElement();
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 );
519
QDomNodePrivate* importNode( const QDomNodePrivate* importedNode, bool deep );
521
// Reimplemented from QDomNodePrivate
522
QDomNodePrivate* cloneNode( bool deep = TRUE );
523
bool isDocument() { return TRUE; }
524
QDomNode::NodeType nodeType() const { return QDomNode::DocumentNode; }
526
void save( QTextStream&, int, int ) const;
529
QDomImplementationPrivate* impl;
530
QDomDocumentTypePrivate* type;
533
/**************************************************************
537
**************************************************************/
539
class QDomHandler : public QXmlDefaultHandler
542
QDomHandler( QDomDocumentPrivate* d, bool namespaceProcessing );
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 );
554
bool fatalError( const QXmlParseException& exception );
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 );
565
bool externalEntityDecl( const QString &name, const QString &publicId, const QString &systemId ) ;
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 ) ;
576
QDomDocumentPrivate *doc;
577
QDomNodePrivate *node;
583
/**************************************************************
585
* QDomImplementationPrivate
587
**************************************************************/
589
QDomImplementationPrivate::QDomImplementationPrivate()
593
QDomImplementationPrivate::~QDomImplementationPrivate()
597
QDomImplementationPrivate* QDomImplementationPrivate::clone()
599
QDomImplementationPrivate* p = new QDomImplementationPrivate;
600
// We are not interested in this node
605
/**************************************************************
609
**************************************************************/
612
\class QDomImplementation qdom.h
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>.
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.
627
Normally you will use the function QDomDocument::implementation()
628
to get the implementation object.
630
You can create a new document type with createDocumentType() and a
631
new document with createDocument().
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
643
Constructs a QDomImplementation object.
645
QDomImplementation::QDomImplementation()
651
Constructs a copy of \a x.
653
QDomImplementation::QDomImplementation( const QDomImplementation& x )
660
QDomImplementation::QDomImplementation( QDomImplementationPrivate* p )
662
// We want to be co-owners, so increase the reference count
669
Assigns \a x to this DOM implementation.
671
QDomImplementation& QDomImplementation::operator= ( const QDomImplementation& x )
674
x.impl->ref(); // avoid x=x
675
if ( impl && impl->deref() )
683
Returns TRUE if \a x and this DOM implementation object were
684
created from the same QDomDocument; otherwise returns FALSE.
686
bool QDomImplementation::operator==( const QDomImplementation& x ) const
688
return ( impl == x.impl );
692
Returns TRUE if \a x and this DOM implementation object were
693
created from different QDomDocuments; otherwise returns FALSE.
695
bool QDomImplementation::operator!=( const QDomImplementation& x ) const
697
return ( impl != x.impl );
701
Destroys the object and frees its resources.
703
QDomImplementation::~QDomImplementation()
705
if ( impl && impl->deref() )
710
The function returns TRUE if QDom implements the requested \a
711
version of a \a feature; otherwise returns FALSE.
713
The currently supported features and their versions:
715
\header \i Feature \i Version
719
bool QDomImplementation::hasFeature( const QString& feature, const QString& version )
721
if ( feature == "XML" ) {
722
if ( version.isEmpty() || version == "1.0" ) {
726
// ### add DOM level 2 features
731
Creates a document type node for the name \a qName.
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.
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.
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.
745
DOM level 2 does not support any other document type declaration
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.
752
\sa createDocument();
754
QDomDocumentType QDomImplementation::createDocumentType( const QString& qName, const QString& publicId, const QString& systemId )
756
QDomDocumentTypePrivate *dt = new QDomDocumentTypePrivate( 0 );
758
if ( systemId.isNull() ) {
759
dt->publicId = QString::null;
760
dt->systemId = QString::null;
762
dt->publicId = publicId;
763
dt->systemId = systemId;
765
return QDomDocumentType( dt );
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.
773
QDomDocument QDomImplementation::createDocument( const QString& nsURI, const QString& qName, const QDomDocumentType& doctype )
775
QDomDocument doc( doctype );
776
QDomElement root = doc.createElementNS( nsURI, qName );
777
doc.appendChild( root );
782
Returns FALSE if the object was created by
783
QDomDocument::implementation(); otherwise returns TRUE.
785
bool QDomImplementation::isNull()
787
return ( impl == 0 );
790
/**************************************************************
792
* QDomNodeListPrivate
794
**************************************************************/
796
QDomNodeListPrivate::QDomNodeListPrivate( QDomNodePrivate* n_impl )
804
QDomNodeListPrivate::QDomNodeListPrivate( QDomNodePrivate* n_impl, const QString& name )
813
QDomNodeListPrivate::QDomNodeListPrivate( QDomNodePrivate* n_impl, const QString& _nsURI, const QString& localName )
823
QDomNodeListPrivate::~QDomNodeListPrivate()
825
if ( node_impl && node_impl->deref() )
829
bool QDomNodeListPrivate::operator== ( const QDomNodeListPrivate& other ) const
831
return ( node_impl == other.node_impl ) && ( tagname == other.tagname ) ;
834
bool QDomNodeListPrivate::operator!= ( const QDomNodeListPrivate& other ) const
836
return ( node_impl != other.node_impl ) || ( tagname != other.tagname ) ;
839
void QDomNodeListPrivate::createList()
843
timestamp = qt_nodeListTime;
844
QDomNodePrivate* p = node_impl->first;
847
if ( tagname.isNull() ) {
852
} else if ( nsURI.isNull() ) {
853
while ( p && p != node_impl ) {
854
if ( p->isElement() && p->nodeName() == tagname ) {
863
while ( p && p != node_impl && !p->next )
865
if ( p && p != node_impl )
870
while ( p && p != node_impl ) {
871
if ( p->isElement() && p->name==tagname && p->namespaceURI==nsURI ) {
880
while ( p && p != node_impl && !p->next )
882
if ( p && p != node_impl )
889
QDomNodePrivate* QDomNodeListPrivate::item( int index )
893
if ( timestamp < qt_nodeListTime )
895
return list.at( index );
898
uint QDomNodeListPrivate::length() const
902
if ( timestamp < qt_nodeListTime ) {
903
QDomNodeListPrivate *that = (QDomNodeListPrivate*)this;
909
/**************************************************************
913
**************************************************************/
916
\class QDomNodeList qdom.h
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>.
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.
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
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
941
\sa QDomNode::childNodes() QDomDocument::elementsByTagName()
945
Creates an empty node list.
947
QDomNodeList::QDomNodeList()
952
QDomNodeList::QDomNodeList( QDomNodeListPrivate* p )
958
Constructs a copy of \a n.
960
QDomNodeList::QDomNodeList( const QDomNodeList& n )
968
Assigns \a n to this node list.
970
QDomNodeList& QDomNodeList::operator= ( const QDomNodeList& n )
974
if ( impl && impl->deref() )
982
Returns TRUE if the node list \a n and this node list are equal;
983
otherwise returns FALSE.
985
bool QDomNodeList::operator== ( const QDomNodeList& n ) const
987
if ( impl == n.impl )
989
if ( !impl || !n.impl )
991
return (*impl == *n.impl);
995
Returns TRUE the node list \a n and this node list are not equal;
996
otherwise returns FALSE.
998
bool QDomNodeList::operator!= ( const QDomNodeList& n ) const
1000
return !operator==(n);
1004
Destroys the object and frees its resources.
1006
QDomNodeList::~QDomNodeList()
1008
if ( impl && impl->deref() )
1013
Returns the node at position \a index.
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
1021
QDomNode QDomNodeList::item( int index ) const
1026
return QDomNode( impl->item( index ) );
1030
Returns the number of nodes in the list.
1032
This function is the same as count().
1034
uint QDomNodeList::length() const
1038
return impl->length();
1042
\fn uint QDomNodeList::count() const
1044
Returns the number of nodes in the list.
1046
This function is the same as length().
1050
/**************************************************************
1054
**************************************************************/
1056
inline void QDomNodePrivate::setOwnerDocument( QDomDocumentPrivate* doc )
1062
QDomNodePrivate::QDomNodePrivate( QDomDocumentPrivate* doc, QDomNodePrivate *par )
1067
setOwnerDocument( doc );
1072
createdWithDom1Interface = TRUE;
1075
QDomNodePrivate::QDomNodePrivate( QDomNodePrivate* n, bool deep )
1077
setOwnerDocument( n->ownerDocument() );
1086
namespaceURI = n->namespaceURI;
1087
createdWithDom1Interface = n->createdWithDom1Interface;
1092
for ( QDomNodePrivate* x = n->first; x; x = x->next )
1093
appendChild( x->cloneNode( TRUE ) );
1096
QDomNodePrivate::~QDomNodePrivate()
1098
QDomNodePrivate* p = first;
1114
void QDomNodePrivate::clear()
1116
QDomNodePrivate* p = first;
1130
QDomNodePrivate* QDomNodePrivate::namedItem( const QString& n )
1132
QDomNodePrivate* p = first;
1134
if ( p->nodeName() == n )
1142
QDomNamedNodeMapPrivate* QDomNodePrivate::attributes()
1147
QDomNodePrivate* QDomNodePrivate::insertBefore( QDomNodePrivate* newChild, QDomNodePrivate* refChild )
1154
if ( newChild == refChild )
1158
if ( refChild && refChild->parent() != this )
1161
// "mark lists as dirty"
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 )
1172
QDomNodePrivate* n = newChild->first;
1174
n->setParent( this );
1178
// Insert at the beginning ?
1179
if ( !refChild || refChild->prev == 0 ) {
1181
first->prev = newChild->last;
1182
newChild->last->next = first;
1184
last = newChild->last;
1185
first = newChild->first;
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;
1194
// No need to increase the reference since QDomDocumentFragment
1195
// does not decrease the reference.
1197
// Remove the nodes from the fragment
1198
newChild->first = 0;
1203
// No more errors can occur now, so we take
1204
// ownership of the node.
1207
if ( newChild->parent() )
1208
newChild->parent()->removeChild( newChild );
1210
newChild->setParent( this );
1214
first->prev = newChild;
1215
newChild->next = first;
1222
if ( refChild->prev == 0 ) {
1224
first->prev = newChild;
1225
newChild->next = first;
1232
newChild->next = refChild;
1233
newChild->prev = refChild->prev;
1234
refChild->prev->next = newChild;
1235
refChild->prev = newChild;
1240
QDomNodePrivate* QDomNodePrivate::insertAfter( QDomNodePrivate* newChild, QDomNodePrivate* refChild )
1247
if ( newChild == refChild )
1251
if ( refChild && refChild->parent() != this )
1254
// "mark lists as dirty"
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 )
1265
QDomNodePrivate* n = newChild->first;
1267
n->setParent( this );
1271
// Insert at the end
1272
if ( !refChild || refChild->next == 0 ) {
1274
last->next = newChild->first;
1275
newChild->first->prev = last;
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;
1286
// No need to increase the reference since QDomDocumentFragment
1287
// does not decrease the reference.
1289
// Remove the nodes from the fragment
1290
newChild->first = 0;
1295
// Release new node from its current parent
1296
if ( newChild->parent() )
1297
newChild->parent()->removeChild( newChild );
1299
// No more errors can occur now, so we take
1300
// ownership of the node
1303
newChild->setParent( this );
1305
// Insert at the end
1308
last->next = newChild;
1309
newChild->prev = last;
1316
if ( refChild->next == 0 ) {
1318
last->next = newChild;
1319
newChild->prev = last;
1326
newChild->prev = refChild;
1327
newChild->next = refChild->next;
1328
refChild->next->prev = newChild;
1329
refChild->next = newChild;
1334
QDomNodePrivate* QDomNodePrivate::replaceChild( QDomNodePrivate* newChild, QDomNodePrivate* oldChild )
1336
if ( oldChild->parent() != this )
1338
if ( !newChild || !oldChild )
1340
if ( newChild == oldChild )
1343
// mark lists as dirty
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 )
1354
QDomNodePrivate* n = newChild->first;
1356
n->setParent( this );
1361
if ( oldChild->next )
1362
oldChild->next->prev = newChild->last;
1363
if ( oldChild->prev )
1364
oldChild->prev->next = newChild->first;
1366
newChild->last->next = oldChild->next;
1367
newChild->first->prev = oldChild->prev;
1369
if ( first == oldChild )
1370
first = newChild->first;
1371
if ( last == oldChild )
1372
last = newChild->last;
1374
oldChild->setNoParent();
1378
// No need to increase the reference since QDomDocumentFragment
1379
// does not decrease the reference.
1381
// Remove the nodes from the fragment
1382
newChild->first = 0;
1385
// We are no longer interested in the old node
1386
if ( oldChild ) oldChild->deref();
1391
// No more errors can occur now, so we take
1392
// ownership of the node
1395
// Release new node from its current parent
1396
if ( newChild->parent() )
1397
newChild->parent()->removeChild( newChild );
1399
newChild->setParent( this );
1401
if ( oldChild->next )
1402
oldChild->next->prev = newChild;
1403
if ( oldChild->prev )
1404
oldChild->prev->next = newChild;
1406
newChild->next = oldChild->next;
1407
newChild->prev = oldChild->prev;
1409
if ( first == oldChild )
1411
if ( last == oldChild )
1414
oldChild->setNoParent();
1418
// We are no longer interested in the old node
1419
if ( oldChild ) oldChild->deref();
1424
QDomNodePrivate* QDomNodePrivate::removeChild( QDomNodePrivate* oldChild )
1427
if ( oldChild->parent() != this )
1430
// "mark lists as dirty"
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 )
1438
if ( oldChild->next )
1439
oldChild->next->prev = oldChild->prev;
1440
if ( oldChild->prev )
1441
oldChild->prev->next = oldChild->next;
1443
if ( last == oldChild )
1444
last = oldChild->prev;
1445
if ( first == oldChild )
1446
first = oldChild->next;
1448
oldChild->setNoParent();
1452
// We are no longer interested in the old node
1453
if ( oldChild ) oldChild->deref();
1458
QDomNodePrivate* QDomNodePrivate::appendChild( QDomNodePrivate* newChild )
1460
// No reference manipulation needed. Done in insertAfter.
1461
return insertAfter( newChild, 0 );
1464
QDomDocumentPrivate* QDomNodePrivate::ownerDocument()
1466
QDomNodePrivate* p = this;
1467
while ( p && !p->isDocument() ) {
1468
if ( !p->hasParent )
1469
return (QDomDocumentPrivate*)p->ownerNode;
1473
return (QDomDocumentPrivate*)p;
1476
QDomNodePrivate* QDomNodePrivate::cloneNode( bool deep )
1478
QDomNodePrivate* p = new QDomNodePrivate( this, deep );
1479
// We are not interested in this node
1484
static void qNormalizeNode( QDomNodePrivate* n )
1486
QDomNodePrivate* p = n->first;
1487
QDomTextPrivate* t = 0;
1490
if ( p->isText() ) {
1492
QDomNodePrivate* tmp = p->next;
1493
t->appendData( p->nodeValue() );
1494
n->removeChild( p );
1497
t = (QDomTextPrivate*)p;
1506
void QDomNodePrivate::normalize()
1508
// ### This one has moved from QDomElementPrivate to this position. It is
1510
qNormalizeNode( this );
1513
void QDomNodePrivate::save( QTextStream& s, int depth, int indent ) const
1515
const QDomNodePrivate* n = first;
1517
n->save( s, depth, indent );
1522
/**************************************************************
1526
**************************************************************/
1528
#define IMPL ((QDomNodePrivate*)impl)
1531
\class QDomNode qdom.h
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>.
1541
Many functions in the DOM return a QDomNode.
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().
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
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().
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().
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().
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().
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().
1579
The document to which the node belongs is returned by
1582
Adjacent QDomText nodes can be merged into a single node with
1585
\l QDomElement nodes have attributes which can be retrieved with
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
1593
You can write the XML representation of the node to a text stream
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.
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;
1608
n = n.nextSibling();
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
1620
Constructs a \link isNull() null\endlink node.
1622
QDomNode::QDomNode()
1628
Constructs a copy of \a n.
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
1634
QDomNode::QDomNode( const QDomNode& n )
1637
if ( impl ) impl->ref();
1641
Constructs a new node for the data \a n.
1643
QDomNode::QDomNode( QDomNodePrivate* n )
1646
if ( impl ) impl->ref();
1650
Assigns a copy of \a n to this DOM node.
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
1656
QDomNode& QDomNode::operator= ( const QDomNode& n )
1658
if ( n.impl ) n.impl->ref();
1659
if ( impl && impl->deref() ) delete impl;
1666
Returns TRUE if \a n and this DOM node are equal; otherwise
1669
bool QDomNode::operator== ( const QDomNode& n ) const
1671
return ( impl == n.impl );
1675
Returns TRUE if \a n and this DOM node are not equal; otherwise
1678
bool QDomNode::operator!= ( const QDomNode& n ) const
1680
return ( impl != n.impl );
1684
Destroys the object and frees its resources.
1686
QDomNode::~QDomNode()
1688
if ( impl && impl->deref() ) delete impl;
1692
Returns the name of the node.
1694
The meaning of the name depends on the subclass:
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"
1713
QString QDomNode::nodeName() const
1716
return QString::null;
1718
if ( !IMPL->prefix.isEmpty() )
1719
return IMPL->prefix + ":" + IMPL->name;
1724
Returns the value of the node.
1726
The meaning of the value depends on the subclass:
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
1736
All the other subclasses do not have a node value and will return
1739
\sa setNodeValue() nodeName()
1741
QString QDomNode::nodeValue() const
1744
return QString::null;
1749
Sets the node's value to \a v.
1753
void QDomNode::setNodeValue( const QString& v )
1757
IMPL->setNodeValue( v );
1761
\enum QDomNode::NodeType
1763
This enum defines the type of the node:
1765
\value AttributeNode
1767
\value CDATASectionNode
1768
\value EntityReferenceNode
1770
\value ProcessingInstructionNode
1773
\value DocumentTypeNode
1774
\value DocumentFragmentNode
1776
\value BaseNode A QDomNode object, i.e. not a QDomNode subclass.
1777
\value CharacterDataNode
1781
Returns the type of the node.
1783
\sa toAttr(), toCDATASection(), toDocumentFragment(),
1784
toDocument() toDocumentType(), toElement(), toEntityReference(),
1785
toText(), toEntity() toNotation(), toProcessingInstruction(),
1786
toCharacterData(), toComment()
1788
QDomNode::NodeType QDomNode::nodeType() const
1791
return QDomNode::BaseNode;
1792
return IMPL->nodeType();
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).
1799
QDomNode QDomNode::parentNode() const
1803
return QDomNode( IMPL->parent() );
1807
Returns a list of all direct child nodes.
1809
Most often you will call this function on a QDomElement object.
1811
For example, if the XML document looks like this:
1815
<p>Hello <b>you</b></p>
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
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.
1825
\sa firstChild() lastChild()
1827
QDomNodeList QDomNode::childNodes() const
1830
return QDomNodeList();
1831
return QDomNodeList( new QDomNodeListPrivate( impl ) );
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.
1839
\sa lastChild() childNodes()
1841
QDomNode QDomNode::firstChild() const
1845
return QDomNode( IMPL->first );
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.
1853
\sa firstChild() childNodes()
1855
QDomNode QDomNode::lastChild() const
1859
return QDomNode( IMPL->last );
1863
Returns the previous sibling in the document tree. Changing the
1864
returned node will also change the node in the document tree.
1866
For example, if you have XML like this:
1870
<h2>Next heading</h2>
1872
and this QDomNode represents the <p> tag, previousSibling()
1873
will return the node representing the <h1> tag.
1877
QDomNode QDomNode::previousSibling() const
1881
return QDomNode( IMPL->prev );
1885
Returns the next sibling in the document tree. Changing the
1886
returned node will also change the node in the document tree.
1888
If you have XML like this:
1892
<h2>Next heading</h2>
1894
and this QDomNode represents the <p> tag, nextSibling() will
1895
return the node representing the <h2> tag.
1897
\sa previousSibling()
1899
QDomNode QDomNode::nextSibling() const
1903
return QDomNode( IMPL->next );
1907
Returns a named node map of all attributes. Attributes are only
1908
provided for \l{QDomElement}s.
1910
Changing the attributes in the map will also change the attributes
1913
QDomNamedNodeMap QDomNode::attributes() const
1916
return QDomNamedNodeMap();
1918
return QDomNamedNodeMap( impl->attributes() );
1922
Returns the document to which this node belongs.
1924
QDomDocument QDomNode::ownerDocument() const
1927
return QDomDocument();
1928
return QDomDocument( IMPL->ownerDocument() );
1932
Creates a deep (not shallow) copy of the QDomNode.
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
1939
QDomNode QDomNode::cloneNode( bool deep ) const
1943
return QDomNode( IMPL->cloneNode( deep ) );
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
1952
void QDomNode::normalize()
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.
1964
\sa QDomImplementation::hasFeature()
1966
bool QDomNode::isSupported( const QString& feature, const QString& version ) const
1968
QDomImplementation i;
1969
return i.hasFeature( feature, version );
1973
Returns the namespace URI of this node or QString::null if the
1974
node has no namespace URI.
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.
1981
\sa prefix() localName() QDomDocument::createElementNS()
1982
QDomDocument::createAttributeNS()
1984
QString QDomNode::namespaceURI() const
1987
return QString::null;
1988
return IMPL->namespaceURI;
1992
Returns the namespace prefix of the node or QString::null if the
1993
node has no namespace prefix.
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().
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
2009
\sa setPrefix() localName() namespaceURI()
2010
QDomDocument::createElementNS() QDomDocument::createAttributeNS()
2012
QString QDomNode::prefix() const
2015
return QString::null;
2016
return IMPL->prefix;
2020
If the node has a namespace prefix, this function changes the
2021
namespace prefix of the node to \a pre. Otherwise this function
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.
2029
\sa prefix() localName() namespaceURI()
2030
QDomDocument::createElementNS() QDomDocument::createAttributeNS()
2032
void QDomNode::setPrefix( const QString& pre )
2034
if ( !impl || IMPL->prefix.isNull() )
2036
if ( isAttr() || isElement() )
2041
If the node uses namespaces, this function returns the local name
2042
of the node; otherwise it returns QString::null.
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.
2049
\sa prefix() namespaceURI() QDomDocument::createElementNS()
2050
QDomDocument::createAttributeNS()
2052
QString QDomNode::localName() const
2054
if ( !impl || IMPL->createdWithDom1Interface )
2055
return QString::null;
2060
Returns TRUE if the node has attributes; otherwise returns FALSE.
2064
bool QDomNode::hasAttributes() const
2068
return IMPL->hasAttributes();
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
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.
2081
If \a newChild is a QDomDocumentFragment, then the children of the
2082
fragment are removed from the fragment and inserted before \a
2085
Returns a new reference to \a newChild on success or a \link
2086
isNull() null node\endlink on failure.
2088
\sa insertAfter() replaceChild() removeChild() appendChild()
2090
QDomNode QDomNode::insertBefore( const QDomNode& newChild, const QDomNode& refChild )
2094
return QDomNode( IMPL->insertBefore( newChild.impl, refChild.impl ) );
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
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.
2107
If \a newChild is a QDomDocumentFragment, then the children of the
2108
fragment are removed from the fragment and inserted after \a
2111
Returns a new reference to \a newChild on success or a \link
2112
isNull() null node\endlink on failure.
2114
\sa insertBefore() replaceChild() removeChild() appendChild()
2116
QDomNode QDomNode::insertAfter( const QDomNode& newChild, const QDomNode& refChild )
2120
return QDomNode( IMPL->insertAfter( newChild.impl, refChild.impl ) );
2124
Replaces \a oldChild with \a newChild. \a oldChild must be a
2125
direct child of this node.
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.
2131
If \a newChild is a QDomDocumentFragment, then \a oldChild is
2132
replaced by all of the children of the fragment.
2134
Returns a new reference to \a oldChild on success or a \link
2135
isNull() null node\endlink an failure.
2137
\sa insertBefore() insertAfter() removeChild() appendChild()
2139
QDomNode QDomNode::replaceChild( const QDomNode& newChild, const QDomNode& oldChild )
2143
return QDomNode( IMPL->replaceChild( newChild.impl, oldChild.impl ) );
2147
Removes \a oldChild from the list of children. \a oldChild must be
2148
a direct child of this node.
2150
Returns a new reference to \a oldChild on success or a \link
2151
isNull() null node\endlink on failure.
2153
\sa insertBefore() insertAfter() replaceChild() appendChild()
2155
QDomNode QDomNode::removeChild( const QDomNode& oldChild )
2160
if ( oldChild.isNull() )
2163
return QDomNode( IMPL->removeChild( oldChild.impl ) );
2167
Appends \a newChild as the node's last child.
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.
2173
If \a newChild is a QDomDocumentFragment, then the children of the
2174
fragment are removed from the fragment and appended.
2176
Returns a new reference to \a newChild.
2178
\sa insertBefore() insertAfter() replaceChild() removeChild()
2180
QDomNode QDomNode::appendChild( const QDomNode& newChild )
2184
return QDomNode( IMPL->appendChild( newChild.impl ) );
2188
Returns TRUE if the node has one or more children; otherwise
2191
bool QDomNode::hasChildNodes() const
2195
return IMPL->first != 0;
2199
Returns TRUE if this node is null (i.e. if it has no type or
2200
contents); otherwise returns FALSE.
2202
bool QDomNode::isNull() const
2204
return ( impl == 0 );
2208
Converts the node into a null node; if it was not a null node
2209
before, its type and contents are deleted.
2213
void QDomNode::clear()
2215
if ( impl && impl->deref() ) delete impl;
2220
Returns the first direct child node for which nodeName() equals \a
2223
If no such direct child exists, a \link isNull() null node\endlink
2228
QDomNode QDomNode::namedItem( const QString& name ) const
2232
return QDomNode( impl->namedItem( name ) );
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.
2240
void QDomNode::save( QTextStream& str, int indent ) const
2243
IMPL->save( str, 1, indent );
2249
Writes the XML representation of the node \a node and all its
2250
children to the stream \a str.
2252
QTextStream& operator<<( QTextStream& str, const QDomNode& node )
2254
node.save( str, 1 );
2260
Returns TRUE if the node is an attribute; otherwise returns FALSE.
2262
If this function returns TRUE, it does not imply that this object
2263
is a QDomAttribute; you can get the QDomAttribute with
2268
bool QDomNode::isAttr() const
2271
return impl->isAttr();
2276
Returns TRUE if the node is a CDATA section; otherwise returns
2279
If this function returns TRUE, it does not imply that this object
2280
is a QDomCDATASection; you can get the QDomCDATASection with
2283
\sa toCDATASection()
2285
bool QDomNode::isCDATASection() const
2288
return impl->isCDATASection();
2293
Returns TRUE if the node is a document fragment; otherwise returns
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().
2300
\sa toDocumentFragment()
2302
bool QDomNode::isDocumentFragment() const
2305
return impl->isDocumentFragment();
2310
Returns TRUE if the node is a document; otherwise returns FALSE.
2312
If this function returns TRUE, it does not imply that this object
2313
is a QDomDocument; you can get the QDomDocument with toDocument().
2317
bool QDomNode::isDocument() const
2320
return impl->isDocument();
2325
Returns TRUE if the node is a document type; otherwise returns
2328
If this function returns TRUE, it does not imply that this object
2329
is a QDomDocumentType; you can get the QDomDocumentType with
2332
\sa toDocumentType()
2334
bool QDomNode::isDocumentType() const
2337
return impl->isDocumentType();
2342
Returns TRUE if the node is an element; otherwise returns FALSE.
2344
If this function returns TRUE, it does not imply that this object
2345
is a QDomElement; you can get the QDomElement with toElement().
2349
bool QDomNode::isElement() const
2352
return impl->isElement();
2357
Returns TRUE if the node is an entity reference; otherwise returns
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().
2364
\sa toEntityReference()
2366
bool QDomNode::isEntityReference() const
2369
return impl->isEntityReference();
2374
Returns TRUE if the node is a text node; otherwise returns FALSE.
2376
If this function returns TRUE, it does not imply that this object
2377
is a QDomText; you can get the QDomText with toText().
2381
bool QDomNode::isText() const
2384
return impl->isText();
2389
Returns TRUE if the node is an entity; otherwise returns FALSE.
2391
If this function returns TRUE, it does not imply that this object
2392
is a QDomEntity; you can get the QDomEntity with toEntity().
2396
bool QDomNode::isEntity() const
2399
return impl->isEntity();
2404
Returns TRUE if the node is a notation; otherwise returns FALSE.
2406
If this function returns TRUE, it does not imply that this object
2407
is a QDomNotation; you can get the QDomNotation with toNotation().
2411
bool QDomNode::isNotation() const
2414
return impl->isNotation();
2419
Returns TRUE if the node is a processing instruction; otherwise
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().
2426
\sa toProcessingInstruction()
2428
bool QDomNode::isProcessingInstruction() const
2431
return impl->isProcessingInstruction();
2436
Returns TRUE if the node is a character data node; otherwise
2439
If this function returns TRUE, it does not imply that this object
2440
is a QDomCharacterData; you can get the QDomCharacterData with
2443
\sa toCharacterData()
2445
bool QDomNode::isCharacterData() const
2448
return impl->isCharacterData();
2453
Returns TRUE if the node is a comment; otherwise returns FALSE.
2455
If this function returns TRUE, it does not imply that this object
2456
is a QDomComment; you can get the QDomComment with toComment().
2460
bool QDomNode::isComment() const
2463
return impl->isComment();
2469
/**************************************************************
2471
* QDomNamedNodeMapPrivate
2473
**************************************************************/
2475
QDomNamedNodeMapPrivate::QDomNamedNodeMapPrivate( QDomNodePrivate* n )
2479
appendToParent = FALSE;
2482
QDomNamedNodeMapPrivate::~QDomNamedNodeMapPrivate()
2487
QDomNamedNodeMapPrivate* QDomNamedNodeMapPrivate::clone( QDomNodePrivate* p )
2489
QDomNamedNodeMapPrivate* m = new QDomNamedNodeMapPrivate( p );
2490
m->readonly = readonly;
2491
m->appendToParent = appendToParent;
2493
QDictIterator<QDomNodePrivate> it ( map );
2494
for ( ; it.current(); ++it )
2495
m->setNamedItem( it.current()->cloneNode() );
2497
// we are no longer interested in ownership
2502
void QDomNamedNodeMapPrivate::clearMap()
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();
2515
QDomNodePrivate* QDomNamedNodeMapPrivate::namedItem( const QString& name ) const
2517
QDomNodePrivate* p = map[ name ];
2521
QDomNodePrivate* QDomNamedNodeMapPrivate::namedItemNS( const QString& nsURI, const QString& localName ) const
2523
QDictIterator<QDomNodePrivate> it( map );
2524
QDomNodePrivate *n = it.current();
2526
if ( !n->prefix.isNull() ) {
2527
// node has a namespace
2528
if ( n->namespaceURI==nsURI && n->name==localName ) {
2538
QDomNodePrivate* QDomNamedNodeMapPrivate::setNamedItem( QDomNodePrivate* arg )
2540
if ( readonly || !arg )
2543
if ( appendToParent )
2544
return parent->appendChild( arg );
2546
QDomNodePrivate *n = map[ arg->nodeName() ];
2547
// We take a reference
2549
map.insert( arg->nodeName(), arg );
2553
QDomNodePrivate* QDomNamedNodeMapPrivate::setNamedItemNS( QDomNodePrivate* arg )
2555
if ( readonly || !arg )
2558
if ( appendToParent )
2559
return parent->appendChild( arg );
2561
if ( !arg->prefix.isNull() ) {
2562
// node has a namespace
2563
QDomNodePrivate *n = namedItemNS( arg->namespaceURI, arg->name );
2564
// We take a reference
2566
map.insert( arg->nodeName(), arg );
2569
// ### check the following code if it is ok
2570
return setNamedItem( arg );
2574
QDomNodePrivate* QDomNamedNodeMapPrivate::removeNamedItem( const QString& name )
2579
QDomNodePrivate* p = namedItem( name );
2582
if ( appendToParent )
2583
return parent->removeChild( p );
2585
map.remove( p->nodeName() );
2586
// We took a reference, so we have to free one here
2591
QDomNodePrivate* QDomNamedNodeMapPrivate::item( int index ) const
2593
if ( (uint)index >= length() )
2596
QDictIterator<QDomNodePrivate> it( map );
2597
for ( int i = 0; i < index; ++i, ++it )
2599
return it.current();
2602
uint QDomNamedNodeMapPrivate::length() const
2607
bool QDomNamedNodeMapPrivate::contains( const QString& name ) const
2609
return ( map[ name ] != 0 );
2612
bool QDomNamedNodeMapPrivate::containsNS( const QString& nsURI, const QString & localName ) const
2614
return ( namedItemNS( nsURI, localName ) != 0 );
2617
/**************************************************************
2621
**************************************************************/
2623
#define IMPL ((QDomNamedNodeMapPrivate*)impl)
2626
\class QDomNamedNodeMap qdom.h
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>.
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.
2644
The QDomNamedNodeMap is used in three places:
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
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().
2662
Terminology: in this class we use "item" and "node"
2667
Constructs an empty named node map.
2669
QDomNamedNodeMap::QDomNamedNodeMap()
2675
Constructs a copy of \a n.
2677
QDomNamedNodeMap::QDomNamedNodeMap( const QDomNamedNodeMap& n )
2684
QDomNamedNodeMap::QDomNamedNodeMap( QDomNamedNodeMapPrivate* n )
2692
Assigns \a n to this named node map.
2694
QDomNamedNodeMap& QDomNamedNodeMap::operator= ( const QDomNamedNodeMap& n )
2696
if ( impl && impl->deref() )
2706
Returns TRUE if \a n and this named node map are equal; otherwise
2709
bool QDomNamedNodeMap::operator== ( const QDomNamedNodeMap& n ) const
2711
return ( impl == n.impl );
2715
Returns TRUE if \a n and this named node map are not equal;
2716
otherwise returns FALSE.
2718
bool QDomNamedNodeMap::operator!= ( const QDomNamedNodeMap& n ) const
2720
return ( impl != n.impl );
2724
Destroys the object and frees its resources.
2726
QDomNamedNodeMap::~QDomNamedNodeMap()
2728
if ( impl && impl->deref() )
2733
Returns the node called \a name.
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().
2739
\sa setNamedItem() namedItemNS()
2741
QDomNode QDomNamedNodeMap::namedItem( const QString& name ) const
2745
return QDomNode( IMPL->namedItem( name ) );
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().
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.
2756
\sa namedItem() removeNamedItem() setNamedItemNS()
2758
QDomNode QDomNamedNodeMap::setNamedItem( const QDomNode& newNode )
2762
return QDomNode( IMPL->setNamedItem( (QDomNodePrivate*)newNode.impl ) );
2766
Removes the node called \a name from the map.
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.
2772
\sa setNamedItem() namedItem() removeNamedItemNS()
2774
QDomNode QDomNamedNodeMap::removeNamedItem( const QString& name )
2778
return QDomNode( IMPL->removeNamedItem( name ) );
2782
Retrieves the node at position \a index.
2784
This can be used to iterate over the map. Note that the nodes in
2785
the map are ordered arbitrarily.
2789
QDomNode QDomNamedNodeMap::item( int index ) const
2793
return QDomNode( IMPL->item( index ) );
2797
Returns the node associated with the local name \a localName and
2798
the namespace URI \a nsURI.
2800
If the map does not contain such a node, a \link
2801
QDomNode::isNull() null node\endlink is returned.
2803
\sa setNamedItemNS() namedItem()
2805
QDomNode QDomNamedNodeMap::namedItemNS( const QString& nsURI, const QString& localName ) const
2809
return QDomNode( IMPL->namedItemNS( nsURI, localName ) );
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.
2818
\sa namedItemNS() removeNamedItemNS() setNamedItem()
2820
QDomNode QDomNamedNodeMap::setNamedItemNS( const QDomNode& newNode )
2824
return QDomNode( IMPL->setNamedItemNS( (QDomNodePrivate*)newNode.impl ) );
2828
Removes the node with the local name \a localName and the
2829
namespace URI \a nsURI from the map.
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
2836
\sa setNamedItemNS() namedItemNS() removeNamedItem()
2838
QDomNode QDomNamedNodeMap::removeNamedItemNS( const QString& nsURI, const QString& localName )
2842
QDomNodePrivate *n = IMPL->namedItemNS( nsURI, localName );
2845
return QDomNode( IMPL->removeNamedItem( n->name ) );
2849
Returns the number of nodes in the map.
2853
uint QDomNamedNodeMap::length() const
2857
return IMPL->length();
2861
\fn uint QDomNamedNodeMap::count() const
2863
Returns the number of nodes in the map.
2865
This function is the same as length().
2869
Returns TRUE if the map contains a node called \a name; otherwise
2872
bool QDomNamedNodeMap::contains( const QString& name ) const
2876
return IMPL->contains( name );
2881
/**************************************************************
2883
* QDomDocumentTypePrivate
2885
**************************************************************/
2887
QDomDocumentTypePrivate::QDomDocumentTypePrivate( QDomDocumentPrivate* doc, QDomNodePrivate* parent )
2888
: QDomNodePrivate( doc, parent )
2893
QDomDocumentTypePrivate::QDomDocumentTypePrivate( QDomDocumentTypePrivate* n, bool deep )
2894
: QDomNodePrivate( n, deep )
2897
// Refill the maps with our new children
2898
QDomNodePrivate* p = first;
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 );
2909
QDomDocumentTypePrivate::~QDomDocumentTypePrivate()
2911
if ( entities->deref() )
2913
if ( notations->deref() )
2917
void QDomDocumentTypePrivate::init()
2919
entities = new QDomNamedNodeMapPrivate( this );
2920
notations = new QDomNamedNodeMapPrivate( this );
2921
publicId = QString::null;
2922
systemId = QString::null;
2923
internalSubset = QString::null;
2925
entities->setAppendToParent( TRUE );
2926
notations->setAppendToParent( TRUE );
2929
QDomNodePrivate* QDomDocumentTypePrivate::cloneNode( bool deep)
2931
QDomNodePrivate* p = new QDomDocumentTypePrivate( this, deep );
2932
// We are not interested in this node
2937
QDomNodePrivate* QDomDocumentTypePrivate::insertBefore( QDomNodePrivate* newChild, QDomNodePrivate* refChild )
2939
// Call the origianl implementation
2940
QDomNodePrivate* p = QDomNodePrivate::insertBefore( newChild, refChild );
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 );
2950
QDomNodePrivate* QDomDocumentTypePrivate::insertAfter( QDomNodePrivate* newChild, QDomNodePrivate* refChild )
2952
// Call the origianl implementation
2953
QDomNodePrivate* p = QDomNodePrivate::insertAfter( newChild, refChild );
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 );
2963
QDomNodePrivate* QDomDocumentTypePrivate::replaceChild( QDomNodePrivate* newChild, QDomNodePrivate* oldChild )
2965
// Call the origianl implementation
2966
QDomNodePrivate* p = QDomNodePrivate::replaceChild( newChild, oldChild );
2969
if ( oldChild && oldChild->isEntity() )
2970
entities->map.remove( oldChild->nodeName() );
2971
else if ( oldChild && oldChild->isNotation() )
2972
notations->map.remove( oldChild->nodeName() );
2974
if ( p->isEntity() )
2975
entities->map.insert( p->nodeName(), p );
2976
else if ( p->isNotation() )
2977
notations->map.insert( p->nodeName(), p );
2983
QDomNodePrivate* QDomDocumentTypePrivate::removeChild( QDomNodePrivate* oldChild )
2985
// Call the origianl implementation
2986
QDomNodePrivate* p = QDomNodePrivate::removeChild( oldChild );
2988
if ( p && p->isEntity() )
2989
entities->map.remove( p->nodeName() );
2990
else if ( p && p->isNotation() )
2991
notations->map.remove( p ->nodeName() );
2996
QDomNodePrivate* QDomDocumentTypePrivate::appendChild( QDomNodePrivate* newChild )
2998
return insertAfter( newChild, 0 );
3001
void QDomDocumentTypePrivate::save( QTextStream& s, int, int indent ) const
3003
if ( name.isEmpty() )
3006
s << "<!DOCTYPE " << name;
3008
if ( !publicId.isNull() ) {
3009
s << " PUBLIC \"" << publicId << "\"";
3010
if ( !systemId.isNull() )
3011
s << " \"" << systemId << "\"";
3012
} else if ( !systemId.isNull() ) {
3013
s << " SYSTEM \"" << systemId << "\"";
3016
if ( entities->length()>0 || notations->length()>0 ) {
3019
QDictIterator<QDomNodePrivate> it2( notations->map );
3020
for ( ; it2.current(); ++it2 )
3021
it2.current()->save( s, 0, indent );
3023
QDictIterator<QDomNodePrivate> it( entities->map );
3024
for ( ; it.current(); ++it )
3025
it.current()->save( s, 0, indent );
3033
/**************************************************************
3037
**************************************************************/
3039
#define IMPL ((QDomDocumentTypePrivate*)impl)
3042
\class QDomDocumentType qdom.h
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>.
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.
3064
Creates an empty QDomDocumentType object.
3066
QDomDocumentType::QDomDocumentType() : QDomNode()
3071
Constructs a copy of \a n.
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
3077
QDomDocumentType::QDomDocumentType( const QDomDocumentType& n )
3082
QDomDocumentType::QDomDocumentType( QDomDocumentTypePrivate* n )
3088
Assigns \a n to this document type.
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
3094
QDomDocumentType& QDomDocumentType::operator= ( const QDomDocumentType& n )
3096
return (QDomDocumentType&) QDomNode::operator=( n );
3100
Destroys the object and frees its resources.
3102
QDomDocumentType::~QDomDocumentType()
3107
Returns the name of the document type as specified in the
3108
<!DOCTYPE name> tag.
3112
QString QDomDocumentType::name() const
3115
return QString::null;
3117
return IMPL->nodeName();
3121
Returns a map of all entities described in the DTD.
3123
QDomNamedNodeMap QDomDocumentType::entities() const
3126
return QDomNamedNodeMap();
3127
return QDomNamedNodeMap( IMPL->entities );
3131
Returns a map of all notations described in the DTD.
3133
QDomNamedNodeMap QDomDocumentType::notations() const
3136
return QDomNamedNodeMap();
3137
return QDomNamedNodeMap( IMPL->notations );
3141
Returns the public identifier of the external DTD subset or
3142
QString::null if there is no public identifier.
3144
\sa systemId() internalSubset() QDomImplementation::createDocumentType()
3146
QString QDomDocumentType::publicId() const
3149
return QString::null;
3150
return IMPL->publicId;
3154
Returns the system identifier of the external DTD subset or
3155
QString::null if there is no system identifier.
3157
\sa publicId() internalSubset() QDomImplementation::createDocumentType()
3159
QString QDomDocumentType::systemId() const
3162
return QString::null;
3163
return IMPL->systemId;
3167
Returns the internal subset of the document type or QString::null
3168
if there is no internal subset.
3170
\sa publicId() systemId()
3172
QString QDomDocumentType::internalSubset() const
3175
return QString::null;
3176
return IMPL->internalSubset;
3180
Returns \c DocumentTypeNode.
3182
\sa isDocumentType() QDomNode::toDocumentType()
3184
QDomNode::NodeType QDomDocumentType::nodeType() const
3186
return DocumentTypeNode;
3190
This function overloads QDomNode::isDocumentType().
3192
\sa nodeType() QDomNode::toDocumentType()
3194
bool QDomDocumentType::isDocumentType() const
3201
/**************************************************************
3203
* QDomDocumentFragmentPrivate
3205
**************************************************************/
3207
QDomDocumentFragmentPrivate::QDomDocumentFragmentPrivate( QDomDocumentPrivate* doc, QDomNodePrivate* parent )
3208
: QDomNodePrivate( doc, parent )
3210
name = "#document-fragment";
3213
QDomDocumentFragmentPrivate::QDomDocumentFragmentPrivate( QDomNodePrivate* n, bool deep )
3214
: QDomNodePrivate( n, deep )
3218
QDomDocumentFragmentPrivate::~QDomDocumentFragmentPrivate()
3222
QDomNodePrivate* QDomDocumentFragmentPrivate::cloneNode( bool deep)
3224
QDomNodePrivate* p = new QDomDocumentFragmentPrivate( this, deep );
3225
// We are not interested in this node
3230
/**************************************************************
3232
* QDomDocumentFragment
3234
**************************************************************/
3236
#define IMPL ((QDomDocumentFragmentPrivate*)impl)
3239
\class QDomDocumentFragment qdom.h
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>.
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.
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.
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.
3267
Constructs an empty document fragment.
3269
QDomDocumentFragment::QDomDocumentFragment()
3273
QDomDocumentFragment::QDomDocumentFragment( QDomDocumentFragmentPrivate* n )
3279
Constructs a copy of \a x.
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
3285
QDomDocumentFragment::QDomDocumentFragment( const QDomDocumentFragment& x )
3291
Assigns \a x to this DOM document fragment.
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
3297
QDomDocumentFragment& QDomDocumentFragment::operator= ( const QDomDocumentFragment& x )
3299
return (QDomDocumentFragment&) QDomNode::operator=( x );
3303
Destroys the object and frees its resources.
3305
QDomDocumentFragment::~QDomDocumentFragment()
3310
Returns \c DocumentFragment.
3312
\sa isDocumentFragment() QDomNode::toDocumentFragment()
3314
QDomNode::NodeType QDomDocumentFragment::nodeType() const
3316
return QDomNode::DocumentFragmentNode;
3320
This function reimplements QDomNode::isDocumentFragment().
3322
\sa nodeType() QDomNode::toDocumentFragment()
3324
bool QDomDocumentFragment::isDocumentFragment() const
3331
/**************************************************************
3333
* QDomCharacterDataPrivate
3335
**************************************************************/
3337
QDomCharacterDataPrivate::QDomCharacterDataPrivate( QDomDocumentPrivate* d, QDomNodePrivate* p,
3338
const QString& data )
3339
: QDomNodePrivate( d, p )
3343
name = "#character-data";
3346
QDomCharacterDataPrivate::QDomCharacterDataPrivate( QDomCharacterDataPrivate* n, bool deep )
3347
: QDomNodePrivate( n, deep )
3351
QDomCharacterDataPrivate::~QDomCharacterDataPrivate()
3355
QDomNodePrivate* QDomCharacterDataPrivate::cloneNode( bool deep )
3357
QDomNodePrivate* p = new QDomCharacterDataPrivate( this, deep );
3358
// We are not interested in this node
3363
uint QDomCharacterDataPrivate::dataLength() const
3365
return value.length();
3368
QString QDomCharacterDataPrivate::substringData( unsigned long offset, unsigned long n ) const
3370
return value.mid( offset, n );
3373
void QDomCharacterDataPrivate::insertData( unsigned long offset, const QString& arg )
3375
value.insert( offset, arg );
3378
void QDomCharacterDataPrivate::deleteData( unsigned long offset, unsigned long n )
3380
value.remove( offset, n );
3383
void QDomCharacterDataPrivate::replaceData( unsigned long offset, unsigned long n, const QString& arg )
3385
value.replace( offset, n, arg );
3388
void QDomCharacterDataPrivate::appendData( const QString& arg )
3393
/**************************************************************
3397
**************************************************************/
3399
#define IMPL ((QDomCharacterDataPrivate*)impl)
3402
\class QDomCharacterData qdom.h
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>.
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.
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().
3423
The node type of the node containing this character data is
3424
returned by nodeType().
3426
\sa QDomText QDomComment QDomCDATASection
3430
Constructs an empty character data object.
3432
QDomCharacterData::QDomCharacterData()
3437
Constructs a copy of \a x.
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
3443
QDomCharacterData::QDomCharacterData( const QDomCharacterData& x )
3448
QDomCharacterData::QDomCharacterData( QDomCharacterDataPrivate* n )
3454
Assigns \a x to this character data.
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
3460
QDomCharacterData& QDomCharacterData::operator= ( const QDomCharacterData& x )
3462
return (QDomCharacterData&) QDomNode::operator=( x );
3466
Destroys the object and frees its resources.
3468
QDomCharacterData::~QDomCharacterData()
3473
Returns the string stored in this object.
3475
If the node is a \link isNull() null node\endlink, it will return
3478
QString QDomCharacterData::data() const
3481
return QString::null;
3482
return impl->nodeValue();
3486
Sets this object's string to \a v.
3488
void QDomCharacterData::setData( const QString& v )
3491
impl->setNodeValue( v );
3495
Returns the length of the stored string.
3497
uint QDomCharacterData::length() const
3500
return IMPL->dataLength();
3505
Returns the substring of length \a count from position \a offset.
3507
QString QDomCharacterData::substringData( unsigned long offset, unsigned long count )
3510
return QString::null;
3511
return IMPL->substringData( offset, count );
3515
Appends the string \a arg to the stored string.
3517
void QDomCharacterData::appendData( const QString& arg )
3520
IMPL->appendData( arg );
3524
Inserts the string \a arg into the stored string at position \a offset.
3526
void QDomCharacterData::insertData( unsigned long offset, const QString& arg )
3529
IMPL->insertData( offset, arg );
3533
Deletes a substring of length \a count from position \a offset.
3535
void QDomCharacterData::deleteData( unsigned long offset, unsigned long count )
3538
IMPL->deleteData( offset, count );
3542
Replaces the substring of length \a count starting at position \a
3543
offset with the string \a arg.
3545
void QDomCharacterData::replaceData( unsigned long offset, unsigned long count, const QString& arg )
3548
IMPL->replaceData( offset, count, arg );
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
3557
QDomNode::NodeType QDomCharacterData::nodeType() const
3560
return CharacterDataNode;
3561
return QDomNode::nodeType();
3567
bool QDomCharacterData::isCharacterData() const
3574
/**************************************************************
3578
**************************************************************/
3580
QDomAttrPrivate::QDomAttrPrivate( QDomDocumentPrivate* d, QDomNodePrivate* parent, const QString& name_ )
3581
: QDomNodePrivate( d, parent )
3584
m_specified = FALSE;
3587
QDomAttrPrivate::QDomAttrPrivate( QDomDocumentPrivate* d, QDomNodePrivate* p, const QString& nsURI, const QString& qName )
3588
: QDomNodePrivate( d, p )
3590
qt_split_namespace( prefix, name, qName, !nsURI.isNull() );
3591
namespaceURI = nsURI;
3592
createdWithDom1Interface = FALSE;
3593
m_specified = FALSE;
3596
QDomAttrPrivate::QDomAttrPrivate( QDomAttrPrivate* n, bool deep )
3597
: QDomNodePrivate( n, deep )
3599
m_specified = n->specified();
3602
QDomAttrPrivate::~QDomAttrPrivate()
3606
void QDomAttrPrivate::setNodeValue( const QString& v )
3609
QDomTextPrivate *t = new QDomTextPrivate( 0, this, v );
3610
// keep the refcount balanced: appendChild() does a ref() anyway.
3613
delete removeChild( first );
3618
QDomNodePrivate* QDomAttrPrivate::cloneNode( bool deep )
3620
QDomNodePrivate* p = new QDomAttrPrivate( this, deep );
3621
// We are not interested in this node
3626
bool QDomAttrPrivate::specified() const
3632
Encode an attribute value upon saving.
3634
static QString encodeAttr( const QString& str )
3637
uint len = tmp.length();
3640
if ( tmp[(int)i] == '<' ) {
3641
tmp.replace( i, 1, "<" );
3644
} else if ( tmp[(int)i] == '"' ) {
3645
tmp.replace( i, 1, """ );
3648
} else if ( tmp[(int)i] == '&' ) {
3649
tmp.replace( i, 1, "&" );
3652
} else if ( tmp[(int)i] == '>' && i>=2 && tmp[(int)i-1]==']' && tmp[(int)i-2]==']' ) {
3653
tmp.replace( i, 1, ">" );
3664
void QDomAttrPrivate::save( QTextStream& s, int, int ) const
3666
if ( namespaceURI.isNull() ) {
3667
s << name << "=\"" << encodeAttr( value ) << "\"";
3669
// ### optimize this (see comment of QDomElementPrivate::save()
3670
s << prefix << ":" << name << "=\"" << encodeAttr( value ) << "\""
3671
<< " xmlns:" << prefix << "=\"" << encodeAttr( namespaceURI ) << "\"";
3675
/**************************************************************
3679
**************************************************************/
3681
#define IMPL ((QDomAttrPrivate*)impl)
3684
\class QDomAttr qdom.h
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>.
3694
For example, the following piece of XML produces an element with
3695
no children, but two attributes:
3698
<link href="http://www.trolltech.com" color="red" />
3701
You can access the attributes of an element with code like this:
3704
QDomElement e = //...
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"
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.
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().
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.
3733
Constructs an empty attribute.
3735
QDomAttr::QDomAttr()
3740
Constructs a copy of \a x.
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
3746
QDomAttr::QDomAttr( const QDomAttr& x )
3751
QDomAttr::QDomAttr( QDomAttrPrivate* n )
3757
Assigns \a x to this DOM attribute.
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
3763
QDomAttr& QDomAttr::operator= ( const QDomAttr& x )
3765
return (QDomAttr&) QDomNode::operator=( x );
3769
Destroys the object and frees its resources.
3771
QDomAttr::~QDomAttr()
3776
Returns the attribute's name.
3778
QString QDomAttr::name() const
3781
return QString::null;
3782
return impl->nodeName();
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.
3792
bool QDomAttr::specified() const
3796
return IMPL->specified();
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.
3804
QDomElement QDomAttr::ownerElement() const
3806
if ( !impl && !impl->parent()->isElement() )
3807
return QDomElement();
3808
return QDomElement( (QDomElementPrivate*)(impl->parent()) );
3812
Returns the value of the attribute or QString::null if the
3813
attribute has not been specified.
3815
\sa specified() setValue()
3817
QString QDomAttr::value() const
3820
return QString::null;
3821
return impl->nodeValue();
3825
Sets the attribute's value to \a v.
3829
void QDomAttr::setValue( const QString& v )
3833
impl->setNodeValue( v );
3834
IMPL->m_specified = TRUE;
3838
Returns \link QDomNode::NodeType AttributeNode\endlink.
3840
QDomNode::NodeType QDomAttr::nodeType() const
3842
return AttributeNode;
3848
bool QDomAttr::isAttr() const
3855
/**************************************************************
3857
* QDomElementPrivate
3859
**************************************************************/
3861
QDomElementPrivate::QDomElementPrivate( QDomDocumentPrivate* d, QDomNodePrivate* p,
3862
const QString& tagname )
3863
: QDomNodePrivate( d, p )
3866
m_attr = new QDomNamedNodeMapPrivate( this );
3869
QDomElementPrivate::QDomElementPrivate( QDomDocumentPrivate* d, QDomNodePrivate* p,
3870
const QString& nsURI, const QString& qName )
3871
: QDomNodePrivate( d, p )
3873
qt_split_namespace( prefix, name, qName, !nsURI.isNull() );
3874
namespaceURI = nsURI;
3875
createdWithDom1Interface = FALSE;
3876
m_attr = new QDomNamedNodeMapPrivate( this );
3879
QDomElementPrivate::QDomElementPrivate( QDomElementPrivate* n, bool deep ) :
3880
QDomNodePrivate( n, deep )
3882
m_attr = n->m_attr->clone( this );
3883
// Reference is down to 0, so we set it to 1 here.
3887
QDomElementPrivate::~QDomElementPrivate()
3889
if ( m_attr->deref() )
3893
QDomNodePrivate* QDomElementPrivate::cloneNode( bool deep)
3895
QDomNodePrivate* p = new QDomElementPrivate( this, deep );
3896
// We are not interested in this node
3901
QString QDomElementPrivate::attribute( const QString& name_, const QString& defValue ) const
3903
QDomNodePrivate* n = m_attr->namedItem( name_ );
3907
return n->nodeValue();
3910
QString QDomElementPrivate::attributeNS( const QString& nsURI, const QString& localName, const QString& defValue ) const
3912
QDomNodePrivate* n = m_attr->namedItemNS( nsURI, localName );
3916
return n->nodeValue();
3919
void QDomElementPrivate::setAttribute( const QString& aname, const QString& newValue )
3921
QDomNodePrivate* n = m_attr->namedItem( aname );
3923
n = new QDomAttrPrivate( ownerDocument(), this, aname );
3924
n->setNodeValue( newValue );
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.
3929
m_attr->setNamedItem( n );
3931
n->setNodeValue( newValue );
3935
void QDomElementPrivate::setAttributeNS( const QString& nsURI, const QString& qName, const QString& newValue )
3937
QString prefix, localName;
3938
qt_split_namespace( prefix, localName, qName, TRUE );
3939
QDomNodePrivate* n = m_attr->namedItemNS( nsURI, localName );
3941
n = new QDomAttrPrivate( ownerDocument(), this, nsURI, qName );
3942
n->setNodeValue( newValue );
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.
3947
m_attr->setNamedItem( n );
3949
n->setNodeValue( newValue );
3954
void QDomElementPrivate::removeAttribute( const QString& aname )
3956
QDomNodePrivate* p = m_attr->removeNamedItem( aname );
3957
if ( p && p->count == 0 )
3961
QDomAttrPrivate* QDomElementPrivate::attributeNode( const QString& aname )
3963
return (QDomAttrPrivate*)m_attr->namedItem( aname );
3966
QDomAttrPrivate* QDomElementPrivate::attributeNodeNS( const QString& nsURI, const QString& localName )
3968
return (QDomAttrPrivate*)m_attr->namedItemNS( nsURI, localName );
3971
QDomAttrPrivate* QDomElementPrivate::setAttributeNode( QDomAttrPrivate* newAttr )
3973
QDomNodePrivate* n = m_attr->namedItem( newAttr->nodeName() );
3975
// Referencing is done by the maps
3976
m_attr->setNamedItem( newAttr );
3978
return (QDomAttrPrivate*)n;
3981
QDomAttrPrivate* QDomElementPrivate::setAttributeNodeNS( QDomAttrPrivate* newAttr )
3983
QDomNodePrivate* n = 0;
3984
if ( !newAttr->prefix.isNull() )
3985
n = m_attr->namedItemNS( newAttr->namespaceURI, newAttr->name );
3987
// Referencing is done by the maps
3988
m_attr->setNamedItem( newAttr );
3990
return (QDomAttrPrivate*)n;
3993
QDomAttrPrivate* QDomElementPrivate::removeAttributeNode( QDomAttrPrivate* oldAttr )
3995
return (QDomAttrPrivate*)m_attr->removeNamedItem( oldAttr->nodeName() );
3998
bool QDomElementPrivate::hasAttribute( const QString& aname )
4000
return m_attr->contains( aname );
4003
bool QDomElementPrivate::hasAttributeNS( const QString& nsURI, const QString& localName )
4005
return m_attr->containsNS( nsURI, localName );
4008
QString QDomElementPrivate::text()
4012
QDomNodePrivate* p = first;
4014
if ( p->isText() || p->isCDATASection() )
4015
t += p->nodeValue();
4016
else if ( p->isElement() )
4017
t += ((QDomElementPrivate*)p)->text();
4024
void QDomElementPrivate::save( QTextStream& s, int depth, int indent ) const
4026
if ( !( prev && prev->isText() ) )
4027
for ( int i = 0; i < depth*indent; ++i )
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() ) {
4041
qName = prefix + ":" + name;
4042
nsDecl = " xmlns:" + prefix;
4044
nsDecl += "=\"" + encodeAttr( namespaceURI ) + "\"";
4046
s << "<" << qName << nsDecl;
4048
if ( !m_attr->map.isEmpty() ) {
4050
QDictIterator<QDomNodePrivate> it( m_attr->map );
4051
for ( ; it.current(); ++it ) {
4052
it.current()->save( s, 0, indent );
4059
if ( first->isText() )
4063
QDomNodePrivate::save( s, depth + 1, indent);
4064
if ( !last->isText() )
4065
for( int i = 0; i < depth*indent; ++i )
4068
s << "</" << qName << ">";
4072
if ( !( next && next->isText() ) )
4076
/**************************************************************
4080
**************************************************************/
4082
#define IMPL ((QDomElementPrivate*)impl)
4085
\class QDomElement qdom.h
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>.
4095
Elements have a tagName() and zero or more attributes associated
4096
with them. The tag name can be changed with setTagName().
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().
4106
If you want to access the text of a node use text(), e.g.
4108
QDomElement e = //...
4110
QString s = e.text()
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.
4118
QDomElement element = doc.documentElement();
4119
for( QDomNode n = element.firstChild(); !n.isNull(); n = n.nextSibling() )
4121
QDomText t = n.toText();
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
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().
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.
4143
Constructs an empty element. Use the QDomDocument::createElement()
4144
function to construct elements with content.
4146
QDomElement::QDomElement()
4152
Constructs a copy of \a x.
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
4158
QDomElement::QDomElement( const QDomElement& x )
4163
QDomElement::QDomElement( QDomElementPrivate* n )
4169
Assigns \a x to this DOM element.
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
4175
QDomElement& QDomElement::operator= ( const QDomElement& x )
4177
return (QDomElement&) QDomNode::operator=( x );
4181
Destroys the object and frees its resources.
4183
QDomElement::~QDomElement()
4188
Returns \c ElementNode.
4190
QDomNode::NodeType QDomElement::nodeType() const
4196
Sets this element's tag name to \a name.
4200
void QDomElement::setTagName( const QString& name )
4207
Returns the tag name of this element. For an XML element like this:
4209
<img src="myimg.png">
4211
the tagname would return "img".
4215
QString QDomElement::tagName() const
4218
return QString::null;
4219
return impl->nodeName();
4223
Returns the attribute called \a name. If the attribute does not
4224
exist \a defValue is returned.
4226
\sa setAttribute() attributeNode() setAttributeNode() attributeNS()
4228
QString QDomElement::attribute( const QString& name, const QString& defValue ) const
4232
return IMPL->attribute( name, defValue );
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
4240
\sa attribute() setAttributeNode() setAttributeNS()
4242
void QDomElement::setAttribute( const QString& name, const QString& value )
4246
IMPL->setAttribute( name, value );
4252
void QDomElement::setAttribute( const QString& name, int value )
4255
setAttribute( name, long(value) );
4261
void QDomElement::setAttribute( const QString& name, uint value )
4264
setAttribute( name, ulong(value) );
4270
void QDomElement::setAttribute( const QString& name, long value )
4276
IMPL->setAttribute( name, x );
4282
void QDomElement::setAttribute( const QString& name, ulong value )
4288
IMPL->setAttribute( name, x );
4294
void QDomElement::setAttribute( const QString& name, double value )
4300
IMPL->setAttribute( name, x );
4304
Removes the attribute called name \a name from this element.
4306
\sa setAttribute() attribute() removeAttributeNS()
4308
void QDomElement::removeAttribute( const QString& name )
4312
IMPL->removeAttribute( name );
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.
4320
\sa setAttributeNode() attribute() setAttribute() attributeNodeNS()
4322
QDomAttr QDomElement::attributeNode( const QString& name)
4326
return QDomAttr( IMPL->attributeNode( name ) );
4330
Adds the attribute \a newAttr to this element.
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
4337
\sa attributeNode() setAttribute() setAttributeNodeNS()
4339
QDomAttr QDomElement::setAttributeNode( const QDomAttr& newAttr )
4343
return QDomAttr( IMPL->setAttributeNode( ((QDomAttrPrivate*)newAttr.impl) ) );
4347
Removes the attribute \a oldAttr from the element and returns it.
4349
\sa attributeNode() setAttributeNode()
4351
QDomAttr QDomElement::removeAttributeNode( const QDomAttr& oldAttr )
4354
return QDomAttr(); // ### should this return oldAttr?
4355
return QDomAttr( IMPL->removeAttributeNode( ((QDomAttrPrivate*)oldAttr.impl) ) );
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
4364
\sa elementsByTagNameNS() QDomDocument::elementsByTagName()
4366
QDomNodeList QDomElement::elementsByTagName( const QString& tagname ) const
4368
return QDomNodeList( new QDomNodeListPrivate( impl, tagname ) );
4374
bool QDomElement::isElement() const
4380
Returns a QDomNamedNodeMap containing all this element's attributes.
4382
\sa attribute() setAttribute() attributeNode() setAttributeNode()
4384
QDomNamedNodeMap QDomElement::attributes() const
4387
return QDomNamedNodeMap();
4388
return QDomNamedNodeMap( IMPL->attributes() );
4392
Returns TRUE if this element has an attribute called \a name;
4393
otherwise returns FALSE.
4395
bool QDomElement::hasAttribute( const QString& name ) const
4399
return IMPL->hasAttribute( name );
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.
4407
\sa setAttributeNS() attributeNodeNS() setAttributeNodeNS() attribute()
4409
QString QDomElement::attributeNS( const QString nsURI, const QString& localName, const QString& defValue ) const
4413
return IMPL->attributeNS( nsURI, localName, defValue );
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
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.
4426
\sa attributeNS() setAttributeNodeNS() setAttribute()
4428
void QDomElement::setAttributeNS( const QString nsURI, const QString& qName, const QString& value )
4432
IMPL->setAttributeNS( nsURI, qName, value );
4438
void QDomElement::setAttributeNS( const QString nsURI, const QString& qName, int value )
4441
setAttributeNS( nsURI, qName, long(value) );
4447
void QDomElement::setAttributeNS( const QString nsURI, const QString& qName, uint value )
4450
setAttributeNS( nsURI, qName, ulong(value) );
4456
void QDomElement::setAttributeNS( const QString nsURI, const QString& qName, long value )
4462
IMPL->setAttributeNS( nsURI, qName, x );
4468
void QDomElement::setAttributeNS( const QString nsURI, const QString& qName, ulong value )
4474
IMPL->setAttributeNS( nsURI, qName, x );
4480
void QDomElement::setAttributeNS( const QString nsURI, const QString& qName, double value )
4486
IMPL->setAttributeNS( nsURI, qName, x );
4490
Removes the attribute with the local name \a localName and the
4491
namespace URI \a nsURI from this element.
4493
\sa setAttributeNS() attributeNS() removeAttribute()
4495
void QDomElement::removeAttributeNS( const QString& nsURI, const QString& localName )
4499
QDomNodePrivate *n = IMPL->attributeNodeNS( nsURI, localName );
4502
IMPL->removeAttribute( n->nodeName() );
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.
4511
\sa setAttributeNode() attribute() setAttribute() attributeNodeNS()
4513
QDomAttr QDomElement::attributeNodeNS( const QString& nsURI, const QString& localName )
4517
return QDomAttr( IMPL->attributeNodeNS( nsURI, localName ) );
4521
Adds the attribute \a newAttr to this element.
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.
4528
\sa attributeNodeNS() setAttributeNS() setAttributeNode()
4530
QDomAttr QDomElement::setAttributeNodeNS( const QDomAttr& newAttr )
4534
return QDomAttr( IMPL->setAttributeNodeNS( ((QDomAttrPrivate*)newAttr.impl) ) );
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.
4543
\sa elementsByTagName() QDomDocument::elementsByTagNameNS()
4545
QDomNodeList QDomElement::elementsByTagNameNS( const QString& nsURI, const QString& localName ) const
4547
return QDomNodeList( new QDomNodeListPrivate( impl, nsURI, localName ) );
4551
Returns TRUE if this element has an attribute with the local name
4552
\a localName and the namespace URI \a nsURI; otherwise returns
4555
bool QDomElement::hasAttributeNS( const QString& nsURI, const QString& localName ) const
4559
return IMPL->hasAttributeNS( nsURI, localName );
4563
Returns the element's text or QString::null.
4567
<h1>Hello <b>Qt</b> <![CDATA[<xml is cool>]]></h1>
4570
The function text() of the QDomElement for the <h1> tag,
4571
will return "Hello Qt <xml is cool>".
4573
Comments are ignored by this function. It only evaluates QDomText
4574
and QDomCDATASection objects.
4576
QString QDomElement::text() const
4579
return QString::null;
4580
return IMPL->text();
4585
/**************************************************************
4589
**************************************************************/
4591
QDomTextPrivate::QDomTextPrivate( QDomDocumentPrivate* d, QDomNodePrivate* parent, const QString& value )
4592
: QDomCharacterDataPrivate( d, parent, value )
4597
QDomTextPrivate::QDomTextPrivate( QDomTextPrivate* n, bool deep )
4598
: QDomCharacterDataPrivate( n, deep )
4602
QDomTextPrivate::~QDomTextPrivate()
4606
QDomNodePrivate* QDomTextPrivate::cloneNode( bool deep)
4608
QDomNodePrivate* p = new QDomTextPrivate( this, deep );
4609
// We are not interested in this node
4614
QDomTextPrivate* QDomTextPrivate::splitText( int offset )
4617
qWarning( "QDomText::splitText The node has no parent. So I can not split" );
4621
QDomTextPrivate* t = new QDomTextPrivate( ownerDocument(), 0, value.mid( offset ) );
4622
value.truncate( offset );
4624
parent()->insertAfter( t, this );
4629
void QDomTextPrivate::save( QTextStream& s, int, int ) const
4631
s << encodeAttr( value );
4634
/**************************************************************
4638
**************************************************************/
4640
#define IMPL ((QDomTextPrivate*)impl)
4643
\class QDomText qdom.h
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>.
4653
You can split the text in a QDomText object over two QDomText
4654
objecs with splitText().
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.
4664
Constructs an empty QDomText object.
4666
To construct a QDomText with content, use QDomDocument::createTextNode().
4668
QDomText::QDomText()
4669
: QDomCharacterData()
4674
Constructs a copy of \a x.
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
4680
QDomText::QDomText( const QDomText& x )
4681
: QDomCharacterData( x )
4685
QDomText::QDomText( QDomTextPrivate* n )
4686
: QDomCharacterData( n )
4691
Assigns \a x to this DOM text.
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
4697
QDomText& QDomText::operator= ( const QDomText& x )
4699
return (QDomText&) QDomNode::operator=( x );
4703
Destroys the object and frees its resources.
4705
QDomText::~QDomText()
4710
Returns \c TextNode.
4712
QDomNode::NodeType QDomText::nodeType() const
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.
4723
The function returns the newly created object.
4725
\sa QDomNode::normalize()
4727
QDomText QDomText::splitText( int offset )
4731
return QDomText( IMPL->splitText( offset ) );
4737
bool QDomText::isText() const
4744
/**************************************************************
4746
* QDomCommentPrivate
4748
**************************************************************/
4750
QDomCommentPrivate::QDomCommentPrivate( QDomDocumentPrivate* d, QDomNodePrivate* parent, const QString& value )
4751
: QDomCharacterDataPrivate( d, parent, value )
4756
QDomCommentPrivate::QDomCommentPrivate( QDomCommentPrivate* n, bool deep )
4757
: QDomCharacterDataPrivate( n, deep )
4761
QDomCommentPrivate::~QDomCommentPrivate()
4765
QDomNodePrivate* QDomCommentPrivate::cloneNode( bool deep)
4767
QDomNodePrivate* p = new QDomCommentPrivate( this, deep );
4768
// We are not interested in this node
4773
void QDomCommentPrivate::save( QTextStream& s, int, int ) const
4775
s << "<!--" << value << "-->";
4778
/**************************************************************
4782
**************************************************************/
4784
#define IMPL ((QDomCommentPrivate*)impl)
4787
\class QDomComment qdom.h
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>.
4797
A comment in the parsed XML such as this:
4799
<!-- this is a comment -->
4801
is represented by QDomComment objects in the parsed Dom tree.
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.
4811
Constructs an empty comment. To construct a comment with content,
4812
use the QDomDocument::createComment() function.
4814
QDomComment::QDomComment()
4815
: QDomCharacterData()
4820
Constructs a copy of \a x.
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
4826
QDomComment::QDomComment( const QDomComment& x )
4827
: QDomCharacterData( x )
4831
QDomComment::QDomComment( QDomCommentPrivate* n )
4832
: QDomCharacterData( n )
4837
Assigns \a x to this DOM comment.
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
4843
QDomComment& QDomComment::operator= ( const QDomComment& x )
4845
return (QDomComment&) QDomNode::operator=( x );
4849
Destroys the object and frees its resources.
4851
QDomComment::~QDomComment()
4856
Returns \c CommentNode.
4858
QDomNode::NodeType QDomComment::nodeType() const
4866
bool QDomComment::isComment() const
4873
/**************************************************************
4875
* QDomCDATASectionPrivate
4877
**************************************************************/
4879
QDomCDATASectionPrivate::QDomCDATASectionPrivate( QDomDocumentPrivate* d, QDomNodePrivate* parent,
4880
const QString& value )
4881
: QDomTextPrivate( d, parent, value )
4883
name = "#cdata-section";
4886
QDomCDATASectionPrivate::QDomCDATASectionPrivate( QDomCDATASectionPrivate* n, bool deep )
4887
: QDomTextPrivate( n, deep )
4891
QDomCDATASectionPrivate::~QDomCDATASectionPrivate()
4895
QDomNodePrivate* QDomCDATASectionPrivate::cloneNode( bool deep)
4897
QDomNodePrivate* p = new QDomCDATASectionPrivate( this, deep );
4898
// We are not interested in this node
4903
void QDomCDATASectionPrivate::save( QTextStream& s, int, int ) const
4905
// ### How do we escape "]]>" ?
4906
// "]]>" is not allowed; so there should be none in value anyway
4907
s << "<![CDATA[" << value << "]]>";
4910
/**************************************************************
4914
**************************************************************/
4916
#define IMPL ((QDomCDATASectionPrivate*)impl)
4919
\class QDomCDATASection qdom.h
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>.
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.
4936
Adjacent QDomCDATASection nodes are not merged by the
4937
QDomNode::normalize() function.
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.
4947
Constructs an empty CDATA section. To create a CDATA section with
4948
content, use the QDomDocument::createCDATASection() function.
4950
QDomCDATASection::QDomCDATASection()
4956
Constructs a copy of \a x.
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
4962
QDomCDATASection::QDomCDATASection( const QDomCDATASection& x )
4967
QDomCDATASection::QDomCDATASection( QDomCDATASectionPrivate* n )
4973
Assigns \a x to this CDATA section.
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
4979
QDomCDATASection& QDomCDATASection::operator= ( const QDomCDATASection& x )
4981
return (QDomCDATASection&) QDomNode::operator=( x );
4985
Destroys the object and frees its resources.
4987
QDomCDATASection::~QDomCDATASection()
4992
Returns \c CDATASection.
4994
QDomNode::NodeType QDomCDATASection::nodeType() const
4996
return CDATASectionNode;
5002
bool QDomCDATASection::isCDATASection() const
5009
/**************************************************************
5011
* QDomNotationPrivate
5013
**************************************************************/
5015
QDomNotationPrivate::QDomNotationPrivate( QDomDocumentPrivate* d, QDomNodePrivate* parent,
5016
const QString& aname,
5017
const QString& pub, const QString& sys )
5018
: QDomNodePrivate( d, parent )
5025
QDomNotationPrivate::QDomNotationPrivate( QDomNotationPrivate* n, bool deep )
5026
: QDomNodePrivate( n, deep )
5032
QDomNotationPrivate::~QDomNotationPrivate()
5036
QDomNodePrivate* QDomNotationPrivate::cloneNode( bool deep)
5038
QDomNodePrivate* p = new QDomNotationPrivate( this, deep );
5039
// We are not interested in this node
5044
void QDomNotationPrivate::save( QTextStream& s, int, int ) const
5046
s << "<!NOTATION " << name << " ";
5047
if ( !m_pub.isNull() ) {
5048
s << "PUBLIC \"" << m_pub << "\"";
5049
if ( !m_sys.isNull() )
5050
s << " \"" << m_sys << "\"";
5052
s << "SYSTEM \"" << m_sys << "\"";
5057
/**************************************************************
5061
**************************************************************/
5063
#define IMPL ((QDomNotationPrivate*)impl)
5066
\class QDomNotation qdom.h
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>.
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).
5081
DOM does not support editing notation nodes; they are therefore
5084
A notation node does not have any parent.
5086
You can retrieve the publicId() and systemId() from a notation
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.
5100
QDomNotation::QDomNotation()
5106
Constructs a copy of \a x.
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
5112
QDomNotation::QDomNotation( const QDomNotation& x )
5117
QDomNotation::QDomNotation( QDomNotationPrivate* n )
5123
Assigns \a x to this DOM notation.
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
5129
QDomNotation& QDomNotation::operator= ( const QDomNotation& x )
5131
return (QDomNotation&) QDomNode::operator=( x );
5135
Destroys the object and frees its resources.
5137
QDomNotation::~QDomNotation()
5142
Returns \c NotationNode.
5144
QDomNode::NodeType QDomNotation::nodeType() const
5146
return NotationNode;
5150
Returns the public identifier of this notation.
5152
QString QDomNotation::publicId() const
5155
return QString::null;
5160
Returns the system identifier of this notation.
5162
QString QDomNotation::systemId() const
5165
return QString::null;
5172
bool QDomNotation::isNotation() const
5179
/**************************************************************
5183
**************************************************************/
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 )
5193
m_notationName = notation;
5196
QDomEntityPrivate::QDomEntityPrivate( QDomEntityPrivate* n, bool deep )
5197
: QDomNodePrivate( n, deep )
5201
m_notationName = n->m_notationName;
5204
QDomEntityPrivate::~QDomEntityPrivate()
5208
QDomNodePrivate* QDomEntityPrivate::cloneNode( bool deep)
5210
QDomNodePrivate* p = new QDomEntityPrivate( this, deep );
5211
// We are not interested in this node
5217
Encode an entity value upon saving.
5219
static QCString encodeEntity( const QCString& str )
5221
QCString tmp( str );
5222
uint len = tmp.length();
5224
const char* d = tmp.data();
5227
tmp.replace( i, 1, "<" );
5232
else if ( d[i] == '"' ) {
5233
tmp.replace( i, 1, """ );
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, "&" );
5252
void QDomEntityPrivate::save( QTextStream& s, int, int ) const
5254
if ( m_sys.isNull() && m_pub.isNull() ) {
5255
s << "<!ENTITY " << name << " \"" << encodeEntity( value.utf8() ) << "\">" << endl;
5257
s << "<!ENTITY " << name << " ";
5258
if ( m_pub.isNull() ) {
5259
s << "SYSTEM \"" << m_sys << "\"";
5261
s << "PUBLIC \"" << m_pub << "\" \"" << m_sys << "\"";
5263
if (! m_notationName.isNull() ) {
5264
s << " NDATA " << m_notationName;
5270
/**************************************************************
5274
**************************************************************/
5276
#define IMPL ((QDomEntityPrivate*)impl)
5279
\class QDomEntity qdom.h
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>.
5289
This class represents an entity in an XML document, either parsed
5290
or unparsed. Note that this models the entity itself not the
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.
5300
An entity node does not have any parent.
5302
You can access the entity's publicId(), systemId() and
5303
notationName() when available.
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.
5314
Constructs an empty entity.
5316
QDomEntity::QDomEntity()
5323
Constructs a copy of \a x.
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
5329
QDomEntity::QDomEntity( const QDomEntity& x )
5334
QDomEntity::QDomEntity( QDomEntityPrivate* n )
5340
Assigns \a x to this DOM entity.
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
5346
QDomEntity& QDomEntity::operator= ( const QDomEntity& x )
5348
return (QDomEntity&) QDomNode::operator=( x );
5352
Destroys the object and frees its resources.
5354
QDomEntity::~QDomEntity()
5359
Returns \c EntityNode.
5361
QDomNode::NodeType QDomEntity::nodeType() const
5367
Returns the public identifier associated with this entity. If the
5368
public identifier was not specified QString::null is returned.
5370
QString QDomEntity::publicId() const
5373
return QString::null;
5378
Returns the system identifier associated with this entity. If the
5379
system identifier was not specified QString::null is returned.
5381
QString QDomEntity::systemId() const
5384
return QString::null;
5389
For unparsed entities this function returns the name of the
5390
notation for the entity. For parsed entities this function returns
5393
QString QDomEntity::notationName() const
5396
return QString::null;
5397
return IMPL->m_notationName;
5403
bool QDomEntity::isEntity() const
5410
/**************************************************************
5412
* QDomEntityReferencePrivate
5414
**************************************************************/
5416
QDomEntityReferencePrivate::QDomEntityReferencePrivate( QDomDocumentPrivate* d, QDomNodePrivate* parent, const QString& aname )
5417
: QDomNodePrivate( d, parent )
5422
QDomEntityReferencePrivate::QDomEntityReferencePrivate( QDomNodePrivate* n, bool deep )
5423
: QDomNodePrivate( n, deep )
5427
QDomEntityReferencePrivate::~QDomEntityReferencePrivate()
5431
QDomNodePrivate* QDomEntityReferencePrivate::cloneNode( bool deep)
5433
QDomNodePrivate* p = new QDomEntityReferencePrivate( this, deep );
5434
// We are not interested in this node
5439
void QDomEntityReferencePrivate::save( QTextStream& s, int, int ) const
5441
s << "&" << name << ";";
5444
/**************************************************************
5446
* QDomEntityReference
5448
**************************************************************/
5450
#define IMPL ((QDomEntityReferencePrivate*)impl)
5453
\class QDomEntityReference qdom.h
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>.
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.
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
5472
Moreover, the XML processor may completely expand references to
5473
entities while building the DOM tree, instead of providing
5474
QDomEntityReference objects.
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.
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.
5491
Constructs an empty entity reference. Use
5492
QDomDocument::createEntityReference() to create a entity reference
5495
QDomEntityReference::QDomEntityReference()
5501
Constructs a copy of \a x.
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
5507
QDomEntityReference::QDomEntityReference( const QDomEntityReference& x )
5512
QDomEntityReference::QDomEntityReference( QDomEntityReferencePrivate* n )
5518
Assigns \a x to this entity reference.
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
5524
QDomEntityReference& QDomEntityReference::operator= ( const QDomEntityReference& x )
5526
return (QDomEntityReference&) QDomNode::operator=( x );
5530
Destroys the object and frees its resources.
5532
QDomEntityReference::~QDomEntityReference()
5537
Returns \c EntityReference.
5539
QDomNode::NodeType QDomEntityReference::nodeType() const
5541
return EntityReferenceNode;
5547
bool QDomEntityReference::isEntityReference() const
5554
/**************************************************************
5556
* QDomProcessingInstructionPrivate
5558
**************************************************************/
5560
QDomProcessingInstructionPrivate::QDomProcessingInstructionPrivate( QDomDocumentPrivate* d,
5561
QDomNodePrivate* parent, const QString& target, const QString& data )
5562
: QDomNodePrivate( d, parent )
5568
QDomProcessingInstructionPrivate::QDomProcessingInstructionPrivate( QDomProcessingInstructionPrivate* n, bool deep )
5569
: QDomNodePrivate( n, deep )
5573
QDomProcessingInstructionPrivate::~QDomProcessingInstructionPrivate()
5577
QDomNodePrivate* QDomProcessingInstructionPrivate::cloneNode( bool deep)
5579
QDomNodePrivate* p = new QDomProcessingInstructionPrivate( this, deep );
5580
// We are not interested in this node
5585
void QDomProcessingInstructionPrivate::save( QTextStream& s, int, int ) const
5587
s << "<?" << name << " " << value << "?>" << endl;
5590
/**************************************************************
5592
* QDomProcessingInstruction
5594
**************************************************************/
5596
#define IMPL ((QDomProcessingInstructionPrivate*)impl)
5599
\class QDomProcessingInstruction qdom.h
5601
\brief The QDomProcessingInstruction class represents an XML processing
5603
\if defined(commercial)
5604
It is part of the <a href="commercialeditions.html">Qt Enterprise Edition</a>.
5610
Processing instructions are used in XML to keep processor-specific
5611
information in the text of the document.
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().
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.
5625
Constructs an empty processing instruction. Use
5626
QDomDocument::createProcessingInstruction() to create a processing
5627
instruction with content.
5629
QDomProcessingInstruction::QDomProcessingInstruction()
5635
Constructs a copy of \a x.
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
5641
QDomProcessingInstruction::QDomProcessingInstruction( const QDomProcessingInstruction& x )
5646
QDomProcessingInstruction::QDomProcessingInstruction( QDomProcessingInstructionPrivate* n )
5652
Assigns \a x to this processing instruction.
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
5658
QDomProcessingInstruction& QDomProcessingInstruction::operator= ( const QDomProcessingInstruction& x )
5660
return (QDomProcessingInstruction&) QDomNode::operator=( x );
5664
Destroys the object and frees its resources.
5666
QDomProcessingInstruction::~QDomProcessingInstruction()
5671
Returns \c ProcessingInstructionNode.
5673
QDomNode::NodeType QDomProcessingInstruction::nodeType() const
5675
return ProcessingInstructionNode;
5679
Returns the target of this processing instruction.
5683
QString QDomProcessingInstruction::target() const
5686
return QString::null;
5687
return impl->nodeName();
5691
Returns the content of this processing instruction.
5693
\sa setData() target()
5695
QString QDomProcessingInstruction::data() const
5698
return QString::null;
5699
return impl->nodeValue();
5703
Sets the data contained in the processing instruction to \a d.
5707
void QDomProcessingInstruction::setData( const QString& d )
5711
impl->setNodeValue( d );
5717
bool QDomProcessingInstruction::isProcessingInstruction() const
5724
/**************************************************************
5726
* QDomDocumentPrivate
5728
**************************************************************/
5730
QDomDocumentPrivate::QDomDocumentPrivate()
5731
: QDomNodePrivate( 0 )
5733
impl = new QDomImplementationPrivate();
5734
type = new QDomDocumentTypePrivate( this, this );
5739
QDomDocumentPrivate::QDomDocumentPrivate( const QString& aname )
5740
: QDomNodePrivate( 0 )
5742
impl = new QDomImplementationPrivate();
5743
type = new QDomDocumentTypePrivate( this, this );
5749
QDomDocumentPrivate::QDomDocumentPrivate( QDomDocumentTypePrivate* dt )
5750
: QDomNodePrivate( 0 )
5752
impl = new QDomImplementationPrivate();
5757
type = new QDomDocumentTypePrivate( this, this );
5763
QDomDocumentPrivate::QDomDocumentPrivate( QDomDocumentPrivate* n, bool deep )
5764
: QDomNodePrivate( n, deep )
5766
impl = n->impl->clone();
5767
// Reference count is down to 0, so we set it to 1 here.
5769
type = (QDomDocumentTypePrivate*)n->type->cloneNode();
5770
type->setParent( this );
5771
// Reference count is down to 0, so we set it to 1 here.
5775
QDomDocumentPrivate::~QDomDocumentPrivate()
5777
if ( impl->deref() ) delete impl;
5778
if ( type->deref() ) delete type;
5781
void QDomDocumentPrivate::clear()
5783
if ( impl->deref() ) delete impl;
5784
if ( type->deref() ) delete type;
5787
QDomNodePrivate::clear();
5790
bool QDomDocumentPrivate::setContent( QXmlInputSource *source, bool namespaceProcessing, QString *errorMsg, int *errorLine, int *errorColumn )
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 );
5797
reader.setFeature( "http://xml.org/sax/features/namespaces", FALSE );
5798
reader.setFeature( "http://xml.org/sax/features/namespace-prefixes", TRUE );
5800
reader.setFeature( "http://trolltech.com/xml/features/report-whitespace-only-CharData", FALSE );
5802
return setContent( source, &reader, errorMsg, errorLine, errorColumn );
5805
bool QDomDocumentPrivate::setContent( QXmlInputSource *source, QXmlReader *reader, QString *errorMsg, int *errorLine, int *errorColumn )
5808
impl = new QDomImplementationPrivate;
5809
type = new QDomDocumentTypePrivate( this, this );
5811
bool namespaceProcessing = reader->feature( "http://xml.org/sax/features/namespaces" )
5812
&& !reader->feature( "http://xml.org/sax/features/namespace-prefixes" );
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 );
5821
if ( !reader->parse( source ) ) {
5823
*errorMsg = hnd.errorMsg;
5825
*errorLine = hnd.errorLine;
5827
*errorColumn = hnd.errorColumn;
5834
QDomNodePrivate* QDomDocumentPrivate::cloneNode( bool deep)
5836
QDomNodePrivate* p = new QDomDocumentPrivate( this, deep );
5837
// We are not interested in this node
5842
QDomElementPrivate* QDomDocumentPrivate::documentElement()
5844
QDomNodePrivate* p = first;
5845
while ( p && !p->isElement() )
5848
return (QDomElementPrivate*)p;
5851
QDomElementPrivate* QDomDocumentPrivate::createElement( const QString& tagName )
5853
QDomElementPrivate* e = new QDomElementPrivate( this, 0, tagName );
5858
QDomElementPrivate* QDomDocumentPrivate::createElementNS( const QString& nsURI, const QString& qName )
5860
QDomElementPrivate* e = new QDomElementPrivate( this, 0, nsURI, qName );
5865
QDomDocumentFragmentPrivate* QDomDocumentPrivate::createDocumentFragment()
5867
QDomDocumentFragmentPrivate* f = new QDomDocumentFragmentPrivate( this, (QDomNodePrivate*)0 );
5872
QDomTextPrivate* QDomDocumentPrivate::createTextNode( const QString& data )
5874
QDomTextPrivate* t = new QDomTextPrivate( this, 0, data );
5879
QDomCommentPrivate* QDomDocumentPrivate::createComment( const QString& data )
5881
QDomCommentPrivate* c = new QDomCommentPrivate( this, 0, data );
5886
QDomCDATASectionPrivate* QDomDocumentPrivate::createCDATASection( const QString& data )
5888
QDomCDATASectionPrivate* c = new QDomCDATASectionPrivate( this, 0, data );
5893
QDomProcessingInstructionPrivate* QDomDocumentPrivate::createProcessingInstruction( const QString& target, const QString& data )
5895
QDomProcessingInstructionPrivate* p = new QDomProcessingInstructionPrivate( this, 0, target, data );
5900
QDomAttrPrivate* QDomDocumentPrivate::createAttribute( const QString& aname )
5902
QDomAttrPrivate* a = new QDomAttrPrivate( this, 0, aname );
5907
QDomAttrPrivate* QDomDocumentPrivate::createAttributeNS( const QString& nsURI, const QString& qName )
5909
QDomAttrPrivate* a = new QDomAttrPrivate( this, 0, nsURI, qName );
5914
QDomEntityReferencePrivate* QDomDocumentPrivate::createEntityReference( const QString& aname )
5916
QDomEntityReferencePrivate* e = new QDomEntityReferencePrivate( this, 0, aname );
5921
QDomNodePrivate* QDomDocumentPrivate::importNode( const QDomNodePrivate* importedNode, bool deep )
5923
QDomNodePrivate *node = 0;
5924
switch ( importedNode->nodeType() ) {
5925
case QDomNode::AttributeNode:
5926
node = new QDomAttrPrivate( (QDomAttrPrivate*)importedNode, TRUE );
5928
case QDomNode::DocumentFragmentNode:
5929
node = new QDomDocumentFragmentPrivate( (QDomDocumentFragmentPrivate*)importedNode, deep );
5931
case QDomNode::ElementNode:
5932
node = new QDomElementPrivate( (QDomElementPrivate*)importedNode, deep );
5934
case QDomNode::EntityNode:
5935
node = new QDomEntityPrivate( (QDomEntityPrivate*)importedNode, deep );
5937
case QDomNode::EntityReferenceNode:
5938
node = new QDomEntityReferencePrivate( (QDomEntityReferencePrivate*)importedNode, FALSE );
5940
case QDomNode::NotationNode:
5941
node = new QDomNotationPrivate( (QDomNotationPrivate*)importedNode, deep );
5943
case QDomNode::ProcessingInstructionNode:
5944
node = new QDomProcessingInstructionPrivate( (QDomProcessingInstructionPrivate*)importedNode, deep );
5946
case QDomNode::TextNode:
5947
node = new QDomTextPrivate( (QDomTextPrivate*)importedNode, deep );
5949
case QDomNode::CDATASectionNode:
5950
node = new QDomCDATASectionPrivate( (QDomCDATASectionPrivate*)importedNode, deep );
5952
case QDomNode::CommentNode:
5953
node = new QDomCommentPrivate( (QDomCommentPrivate*)importedNode, deep );
5959
node->setOwnerDocument( this );
5960
// The QDomNode constructor increases the refcount, so deref() first to
5961
// keep refcount balanced.
5967
void QDomDocumentPrivate::save( QTextStream& s, int, int indent ) const
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);
5981
if ( enc.isEmpty() ) {
5982
s.setEncoding( QTextStream::UnicodeUTF8 );
5984
s.setCodec( QTextCodec::codecForName( enc ) );
5987
s.setEncoding( QTextStream::UnicodeUTF8 );
5990
if ( !doc && !(n->isProcessingInstruction()&&n->nodeName()=="xml") ) {
5991
// save doctype after XML declaration
5992
type->save( s, 0, indent );
5995
n->save( s, 0, indent );
6000
/**************************************************************
6004
**************************************************************/
6006
#define IMPL ((QDomDocumentPrivate*)impl)
6009
\class QDomDocument qdom.h
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>.
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.
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.
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.
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.
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
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().
6058
It is possible to insert a node from another document into the
6059
document using importNode().
6061
You can obtain a list of all the elements that have a particular
6062
tag with elementsByTagName() or with elementsByTagNameNS().
6064
The QDom classes are typically used as follows:
6066
QDomDocument doc( "mydocument" );
6067
QFile file( "mydocument.xml" );
6068
if ( !file.open( IO_ReadOnly ) )
6070
if ( !doc.setContent( &file ) ) {
6076
// print out the element names of all elements that are direct children
6077
// of the outermost element.
6078
QDomElement docElem = doc.documentElement();
6080
QDomNode n = docElem.firstChild();
6081
while( !n.isNull() ) {
6082
QDomElement e = n.toElement(); // try to convert the node to an element.
6084
cout << e.tagName() << endl; // the node really is an element.
6086
n = n.nextSibling();
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 );
6095
Once \c doc and \c elem go out of scope, the whole internal tree
6096
representing the XML document is deleted.
6098
To create a document using DOM use code like this:
6100
QDomDocument doc( "MyML" );
6101
QDomElement root = doc.createElement( "MyML" );
6102
doc.appendChild( root );
6104
QDomElement tag = doc.createElement( "Greeting" );
6105
root.appendChild( tag );
6107
QDomText t = doc.createTextNode( "Hello World" );
6108
tag.appendChild( t );
6110
QString xml = doc.toString();
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.
6122
Constructs an empty document.
6124
QDomDocument::QDomDocument()
6126
impl = new QDomDocumentPrivate;
6130
Creates a document and sets the name of the document type to \a
6133
QDomDocument::QDomDocument( const QString& name )
6135
// We take over ownership
6136
impl = new QDomDocumentPrivate( name );
6140
Creates a document with the document type \a doctype.
6142
\sa QDomImplementation::createDocumentType()
6144
QDomDocument::QDomDocument( const QDomDocumentType& doctype )
6146
impl = new QDomDocumentPrivate( (QDomDocumentTypePrivate*)(doctype.impl) );
6150
Constructs a copy of \a x.
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
6156
QDomDocument::QDomDocument( const QDomDocument& x )
6161
QDomDocument::QDomDocument( QDomDocumentPrivate* x )
6167
Assigns \a x to this DOM document.
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
6173
QDomDocument& QDomDocument::operator= ( const QDomDocument& x )
6175
return (QDomDocument&) QDomNode::operator=( x );
6179
Destroys the object and frees its resources.
6181
QDomDocument::~QDomDocument()
6188
This function reads the XML document from the string \a text.
6189
Since \a text is already a Unicode string, no encoding detection
6192
bool QDomDocument::setContent( const QString& text, bool namespaceProcessing, QString *errorMsg, int *errorLine, int *errorColumn )
6195
impl = new QDomDocumentPrivate;
6196
QXmlInputSource source;
6197
source.setData( text );
6198
return IMPL->setContent( &source, namespaceProcessing, errorMsg, errorLine, errorColumn );
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
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
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.
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.
6223
If \a namespaceProcessing is FALSE, the functions
6224
QDomNode::prefix(), QDomNode::localName() and
6225
QDomNode::namespaceURI() return QString::null.
6227
\sa QDomNode::namespaceURI() QDomNode::localName()
6228
QDomNode::prefix() QString::isNull() QString::isEmpty()
6230
bool QDomDocument::setContent( const QByteArray& buffer, bool namespaceProcessing, QString *errorMsg, int *errorLine, int *errorColumn )
6233
impl = new QDomDocumentPrivate;
6234
QBuffer buf( buffer );
6235
QXmlInputSource source( &buf );
6236
return IMPL->setContent( &source, namespaceProcessing, errorMsg, errorLine, errorColumn );
6242
This function reads the XML document from the C string \a buffer.
6244
\warning This function does not try to detect the encoding:
6245
instead it assumes that the C string is UTF-8 encoded.
6247
bool QDomDocument::setContent( const QCString& buffer, bool namespaceProcessing, QString *errorMsg, int *errorLine, int *errorColumn )
6249
return setContent( QString::fromUtf8( buffer, buffer.length() ), namespaceProcessing, errorMsg, errorLine, errorColumn );
6255
This function reads the XML document from the IO device \a dev.
6257
bool QDomDocument::setContent( QIODevice* dev, bool namespaceProcessing, QString *errorMsg, int *errorLine, int *errorColumn )
6260
impl = new QDomDocumentPrivate;
6261
QXmlInputSource source( dev );
6262
return IMPL->setContent( &source, namespaceProcessing, errorMsg, errorLine, errorColumn );
6268
This function reads the XML document from the string \a text.
6269
Since \a text is already a Unicode string, no encoding detection
6272
No namespace processing is performed either.
6274
bool QDomDocument::setContent( const QString& text, QString *errorMsg, int *errorLine, int *errorColumn )
6276
return setContent( text, FALSE, errorMsg, errorLine, errorColumn );
6282
This function reads the XML document from the byte array \a
6285
No namespace processing is performed.
6287
bool QDomDocument::setContent( const QByteArray& buffer, QString *errorMsg, int *errorLine, int *errorColumn )
6289
return setContent( buffer, FALSE, errorMsg, errorLine, errorColumn );
6295
This function reads the XML document from the C string \a buffer.
6297
No namespace processing is performed.
6299
\warning This function does not try to detect the encoding:
6300
instead it assumes that the C string is UTF-8 encoded.
6302
bool QDomDocument::setContent( const QCString& buffer, QString *errorMsg, int *errorLine, int *errorColumn )
6304
return setContent( buffer, FALSE, errorMsg, errorLine, errorColumn );
6310
This function reads the XML document from the IO device \a dev.
6312
No namespace processing is performed.
6314
bool QDomDocument::setContent( QIODevice* dev, QString *errorMsg, int *errorLine, int *errorColumn )
6316
return setContent( dev, FALSE, errorMsg, errorLine, errorColumn );
6322
This function reads the XML document from the QXmlInputSource \a source and
6323
parses it with the QXmlReader \a reader.
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
6329
\sa QXmlSimpleReader
6331
bool QDomDocument::setContent( QXmlInputSource *source, QXmlReader *reader, QString *errorMsg, int *errorLine, int *errorColumn )
6334
impl = new QDomDocumentPrivate;
6335
return IMPL->setContent( source, reader, errorMsg, errorLine, errorColumn );
6339
Converts the parsed document back to its textual representation.
6343
QString QDomDocument::toString() const
6346
QTextStream s( str, IO_WriteOnly );
6355
This function uses \a indent as the amount of space to indent
6358
QString QDomDocument::toString( int indent ) const
6361
QTextStream s( str, IO_WriteOnly );
6368
Converts the parsed document back to its textual representation
6369
and returns a QCString for that is encoded in UTF-8.
6373
QCString QDomDocument::toCString() const
6375
// ### if there is an encoding specified in the xml declaration, this
6376
// encoding declaration should be changed to utf8
6377
return toString().utf8();
6383
This function uses \a indent as the amount of space to indent
6386
QCString QDomDocument::toCString( int indent ) const
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();
6395
Returns the document type of this document.
6397
QDomDocumentType QDomDocument::doctype() const
6400
return QDomDocumentType();
6401
return QDomDocumentType( IMPL->doctype() );
6405
Returns a QDomImplementation object.
6407
QDomImplementation QDomDocument::implementation() const
6410
return QDomImplementation();
6411
return QDomImplementation( IMPL->implementation() );
6415
Returns the root element of the document.
6417
QDomElement QDomDocument::documentElement() const
6420
return QDomElement();
6421
return QDomElement( IMPL->documentElement() );
6425
Creates a new element called \a tagName that can be inserted into
6426
the DOM tree, e.g. using QDomNode::appendChild().
6428
\sa createElementNS() QDomNode::appendChild() QDomNode::insertBefore()
6429
QDomNode::insertAfter()
6431
QDomElement QDomDocument::createElement( const QString& tagName )
6434
return QDomElement();
6435
return QDomElement( IMPL->createElement( tagName ) );
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
6443
QDomDocumentFragment QDomDocument::createDocumentFragment()
6446
return QDomDocumentFragment();
6447
return QDomDocumentFragment( IMPL->createDocumentFragment() );
6451
Creates a text node for the string \a value that can be inserted
6452
into the document tree, e.g. using QDomNode::appendChild().
6454
\sa QDomNode::appendChild() QDomNode::insertBefore() QDomNode::insertAfter()
6456
QDomText QDomDocument::createTextNode( const QString& value )
6460
return QDomText( IMPL->createTextNode( value ) );
6464
Creates a new comment for the string \a value that can be inserted
6465
into the document, e.g. using QDomNode::appendChild().
6467
\sa QDomNode::appendChild() QDomNode::insertBefore() QDomNode::insertAfter()
6469
QDomComment QDomDocument::createComment( const QString& value )
6472
return QDomComment();
6473
return QDomComment( IMPL->createComment( value ) );
6477
Creates a new CDATA section for the string \a value that can be
6478
inserted into the document, e.g. using QDomNode::appendChild().
6480
\sa QDomNode::appendChild() QDomNode::insertBefore() QDomNode::insertAfter()
6482
QDomCDATASection QDomDocument::createCDATASection( const QString& value )
6485
return QDomCDATASection();
6486
return QDomCDATASection( IMPL->createCDATASection( value ) );
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
6495
\sa QDomNode::appendChild() QDomNode::insertBefore() QDomNode::insertAfter()
6497
QDomProcessingInstruction QDomDocument::createProcessingInstruction( const QString& target,
6498
const QString& data )
6501
return QDomProcessingInstruction();
6502
return QDomProcessingInstruction( IMPL->createProcessingInstruction( target, data ) );
6507
Creates a new attribute called \a name that can be inserted into
6508
an element, e.g. using QDomElement::setAttributeNode().
6510
\sa createAttributeNS()
6512
QDomAttr QDomDocument::createAttribute( const QString& name )
6516
return QDomAttr( IMPL->createAttribute( name ) );
6520
Creates a new entity reference called \a name that can be inserted
6521
into the document, e.g. using QDomNode::appendChild().
6523
\sa QDomNode::appendChild() QDomNode::insertBefore() QDomNode::insertAfter()
6525
QDomEntityReference QDomDocument::createEntityReference( const QString& name )
6528
return QDomEntityReference();
6529
return QDomEntityReference( IMPL->createEntityReference( name ) );
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
6538
\sa elementsByTagNameNS() QDomElement::elementsByTagName()
6540
QDomNodeList QDomDocument::elementsByTagName( const QString& tagname ) const
6542
return QDomNodeList( new QDomNodeListPrivate( impl, tagname ) );
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.
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.
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.
6562
The behavior of this function is slightly different depending on
6565
\header \i Node Type \i Behaviour
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
6577
\row \i QDomDocumentType
6578
\i Document type nodes cannot be imported.
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).
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
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
6596
\row \i QDomProcessingInstruction
6597
\i The target and value of the processing instruction is
6598
copied to the new node.
6600
\i The text is copied to the new node.
6601
\row \i QDomCDATASection
6602
\i The text is copied to the new node.
6604
\i The text is copied to the new node.
6607
\sa QDomElement::setAttribute() QDomNode::insertBefore()
6608
QDomNode::insertAfter() QDomNode::replaceChild() QDomNode::removeChild()
6609
QDomNode::appendChild()
6611
QDomNode QDomDocument::importNode( const QDomNode& importedNode, bool deep )
6615
return QDomNode( IMPL->importNode( importedNode.impl, deep ) );
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).
6627
QDomElement QDomDocument::createElementNS( const QString& nsURI, const QString& qName )
6630
return QDomElement();
6631
return QDomElement( IMPL->createElementNS( nsURI, qName ) );
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).
6641
\sa createAttribute()
6643
QDomAttr QDomDocument::createAttributeNS( const QString& nsURI, const QString& qName )
6647
return QDomAttr( IMPL->createAttributeNS( nsURI, qName ) );
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.
6656
\sa elementsByTagName() QDomElement::elementsByTagNameNS()
6658
QDomNodeList QDomDocument::elementsByTagNameNS( const QString& nsURI, const QString& localName )
6660
return QDomNodeList( new QDomNodeListPrivate( impl, nsURI, localName ) );
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.
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.
6672
QDomElement QDomDocument::elementById( const QString& /*elementId*/ )
6674
return QDomElement();
6678
Returns \c DocumentNode.
6680
QDomNode::NodeType QDomDocument::nodeType() const
6682
return DocumentNode;
6688
bool QDomDocument::isDocument() const
6696
/**************************************************************
6698
* Node casting functions
6700
**************************************************************/
6703
Converts a QDomNode into a QDomAttr. If the node is not an
6704
attribute, the returned object will be \link QDomNode::isNull()
6709
QDomAttr QDomNode::toAttr()
6711
if ( impl && impl->isAttr() )
6712
return QDomAttr( ((QDomAttrPrivate*)impl) );
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.
6721
\sa isCDATASection()
6723
QDomCDATASection QDomNode::toCDATASection()
6725
if ( impl && impl->isCDATASection() )
6726
return QDomCDATASection( ((QDomCDATASectionPrivate*)impl) );
6727
return QDomCDATASection();
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.
6735
\sa isDocumentFragment()
6737
QDomDocumentFragment QDomNode::toDocumentFragment()
6739
if ( impl && impl->isDocumentFragment() )
6740
return QDomDocumentFragment( ((QDomDocumentFragmentPrivate*)impl) );
6741
return QDomDocumentFragment();
6745
Converts a QDomNode into a QDomDocument. If the node is not a
6746
document the returned object will be \link QDomNode::isNull()
6751
QDomDocument QDomNode::toDocument()
6753
if ( impl && impl->isDocument() )
6754
return QDomDocument( ((QDomDocumentPrivate*)impl) );
6755
return QDomDocument();
6759
Converts a QDomNode into a QDomDocumentType. If the node is not a
6760
document type the returned object will be \link QDomNode::isNull()
6763
\sa isDocumentType()
6765
QDomDocumentType QDomNode::toDocumentType()
6767
if ( impl && impl->isDocumentType() )
6768
return QDomDocumentType( ((QDomDocumentTypePrivate*)impl) );
6769
return QDomDocumentType();
6773
Converts a QDomNode into a QDomElement. If the node is not an
6774
element the returned object will be \link QDomNode::isNull()
6779
QDomElement QDomNode::toElement()
6781
if ( impl && impl->isElement() )
6782
return QDomElement( ((QDomElementPrivate*)impl) );
6783
return QDomElement();
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.
6791
\sa isEntityReference()
6793
QDomEntityReference QDomNode::toEntityReference()
6795
if ( impl && impl->isEntityReference() )
6796
return QDomEntityReference( ((QDomEntityReferencePrivate*)impl) );
6797
return QDomEntityReference();
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.
6806
QDomText QDomNode::toText()
6808
if ( impl && impl->isText() )
6809
return QDomText( ((QDomTextPrivate*)impl) );
6814
Converts a QDomNode into a QDomEntity. If the node is not an
6815
entity the returned object will be \link QDomNode::isNull()
6820
QDomEntity QDomNode::toEntity()
6822
if ( impl && impl->isEntity() )
6823
return QDomEntity( ((QDomEntityPrivate*)impl) );
6824
return QDomEntity();
6828
Converts a QDomNode into a QDomNotation. If the node is not a
6829
notation the returned object will be \link QDomNode::isNull()
6834
QDomNotation QDomNode::toNotation()
6836
if ( impl && impl->isNotation() )
6837
return QDomNotation( ((QDomNotationPrivate*)impl) );
6838
return QDomNotation();
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.
6846
\sa isProcessingInstruction()
6848
QDomProcessingInstruction QDomNode::toProcessingInstruction()
6850
if ( impl && impl->isProcessingInstruction() )
6851
return QDomProcessingInstruction( ((QDomProcessingInstructionPrivate*)impl) );
6852
return QDomProcessingInstruction();
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.
6860
\sa isCharacterData()
6862
QDomCharacterData QDomNode::toCharacterData()
6864
if ( impl && impl->isCharacterData() )
6865
return QDomCharacterData( ((QDomCharacterDataPrivate*)impl) );
6866
return QDomCharacterData();
6870
Converts a QDomNode into a QDomComment. If the node is not a
6871
comment the returned object will be \link QDomNode::isNull()
6876
QDomComment QDomNode::toComment()
6878
if ( impl && impl->isComment() )
6879
return QDomComment( ((QDomCommentPrivate*)impl) );
6880
return QDomComment();
6883
/**************************************************************
6887
**************************************************************/
6889
QDomHandler::QDomHandler( QDomDocumentPrivate* adoc, bool namespaceProcessing )
6894
nsProcessing = namespaceProcessing;
6897
QDomHandler::~QDomHandler()
6901
bool QDomHandler::endDocument()
6903
// ### is this really necessary? (rms)
6909
bool QDomHandler::startDTD( const QString& name, const QString& publicId, const QString& systemId )
6911
doc->doctype()->name = name;
6912
doc->doctype()->publicId = publicId;
6913
doc->doctype()->systemId = systemId;
6917
bool QDomHandler::startElement( const QString& nsURI, const QString&, const QString& qName, const QXmlAttributes& atts )
6921
if ( nsProcessing ) {
6922
n = doc->createElementNS( nsURI, qName );
6924
n = doc->createElement( qName );
6926
node->appendChild( n );
6930
for ( int i=0; i<atts.length(); i++ )
6932
if ( nsProcessing ) {
6933
((QDomElementPrivate*)node)->setAttributeNS( atts.uri(i), atts.qName(i), atts.value(i) );
6935
((QDomElementPrivate*)node)->setAttribute( atts.qName(i), atts.value(i) );
6942
bool QDomHandler::endElement( const QString&, const QString&, const QString& )
6946
node = node->parent();
6951
bool QDomHandler::characters( const QString& ch )
6953
// No text as child of some document
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 );
6963
doc->doctype()->appendChild( e );
6964
node->appendChild( doc->createEntityReference( entityName ) );
6966
node->appendChild( doc->createTextNode( ch ) );
6972
bool QDomHandler::processingInstruction( const QString& target, const QString& data )
6974
node->appendChild( doc->createProcessingInstruction( target, data ) );
6978
bool QDomHandler::skippedEntity( const QString& name )
6980
node->appendChild( doc->createEntityReference( name ) );
6984
bool QDomHandler::fatalError( const QXmlParseException& exception )
6986
errorMsg = exception.message();
6987
errorLine = exception.lineNumber();
6988
errorColumn = exception.columnNumber();
6989
return QXmlDefaultHandler::fatalError( exception );
6992
bool QDomHandler::startCDATA()
6998
bool QDomHandler::endCDATA()
7004
bool QDomHandler::startEntity( const QString &name )
7010
bool QDomHandler::endEntity( const QString & )
7012
entityName = QString::null;
7016
bool QDomHandler::comment( const QString& ch )
7018
node->appendChild( doc->createComment( ch ) );
7022
bool QDomHandler::unparsedEntityDecl( const QString &name, const QString &publicId, const QString &systemId, const QString ¬ationName )
7024
QDomEntityPrivate* e = new QDomEntityPrivate( doc, 0, name,
7025
publicId, systemId, notationName );
7026
doc->doctype()->appendChild( e );
7030
bool QDomHandler::externalEntityDecl( const QString &name, const QString &publicId, const QString &systemId )
7032
return unparsedEntityDecl( name, publicId, systemId, QString::null );
7035
bool QDomHandler::notationDecl( const QString & name, const QString & publicId, const QString & systemId )
7037
QDomNotationPrivate* n = new QDomNotationPrivate( doc, 0, name, publicId, systemId );
7038
doc->doctype()->appendChild( n );
7042
} // namespace PsiXml