1
/****************************************************************************
3
** Copyright (C) 1992-2005 Trolltech AS. All rights reserved.
5
** This file is part of the xml module of the Qt Toolkit.
7
** This file may be distributed under the terms of the Q Public License
8
** as defined by Trolltech AS of Norway and appearing in the file
9
** LICENSE.QPL included in the packaging of this file.
11
** This file may be distributed and/or modified under the terms of the
12
** GNU General Public License version 2 as published by the Free Software
13
** Foundation and appearing in the file LICENSE.GPL included in the
14
** packaging of this file.
16
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
17
** information about Qt Commercial License Agreements.
18
** See http://www.trolltech.com/qpl/ for QPL licensing information.
19
** See http://www.trolltech.com/gpl/ for GPL licensing information.
21
** Contact info@trolltech.com if any conditions of this licensing are
24
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
25
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
27
****************************************************************************/
29
#include <qplatformdefs.h>
37
#include <qiodevice.h>
40
#include <qtextcodec.h>
41
#include <qtextstream.h>
47
### old todo comments -- I don't know if they still apply...
49
If the document dies, remove all pointers to it from children
50
which can not be deleted at this time.
52
If a node dies and has direct children which can not be deleted,
53
then remove the pointer to the parent.
55
createElement and friends create double reference counts.
60
Remove emtpy emthods in the *Private classes
62
Make a lot of the (mostly empty) methods in the public classes inline.
63
Specially constructors assignment operators and comparison operators are candidates.
65
The virtual isXxx functions in *Private can probably be replaced by inline methods checking the nodeType().
72
1) If an intern object returns a pointer to another intern object
73
then the reference count of the returned object is not increased.
74
2) If an extern object is created and gets a pointer to some intern
75
object, then the extern object increases the intern objects reference count.
76
3) If an extern object is deleted, then it decreases the reference count
77
on its associated intern object and deletes it if nobody else hold references
83
Helper to split a qualified name in the prefix and local name.
85
static void qt_split_namespace(QString& prefix, QString& name, const QString& qName, bool hasURI)
87
int i = qName.indexOf(':');
95
prefix = qName.left(i);
96
name = qName.mid(i + 1);
100
// ##### shouldn't this be a member of QDomDocumentPrivate?
102
Counter for the QDomNodeListPrivate timestamps.
104
static volatile long qt_nodeListTime = 0;
106
/**************************************************************
108
* Private class declerations
110
**************************************************************/
112
class QDomImplementationPrivate
115
QDomImplementationPrivate() { ref = 1; }
116
QDomImplementationPrivate* clone();
120
class QDomNodePrivate
123
QDomNodePrivate(QDomDocumentPrivate*, QDomNodePrivate* parent = 0);
124
QDomNodePrivate(QDomNodePrivate* n, bool deep);
125
virtual ~QDomNodePrivate();
127
QString nodeName() const { return name; }
128
QString nodeValue() const { return value; }
129
virtual void setNodeValue(const QString& v) { value = v; }
131
QDomDocumentPrivate* ownerDocument();
132
void setOwnerDocument(QDomDocumentPrivate* doc);
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;
173
QDomNodePrivate* prev;
174
QDomNodePrivate* next;
175
QDomNodePrivate* ownerNode; // either the node's parent or the node's owner document
176
QDomNodePrivate* first;
177
QDomNodePrivate* last;
179
QString name; // this is the local name if prefix != null
181
QString prefix; // set this only for ElementNode and AttributeNode
182
QString namespaceURI; // set this only for ElementNode and AttributeNode
183
bool createdWithDom1Interface : 1;
187
class QDomNodeListPrivate
190
QDomNodeListPrivate(QDomNodePrivate*);
191
QDomNodeListPrivate(QDomNodePrivate*, const QString& );
192
QDomNodeListPrivate(QDomNodePrivate*, const QString&, const QString& );
193
~QDomNodeListPrivate();
195
bool operator== (const QDomNodeListPrivate&) const;
196
bool operator!= (const QDomNodeListPrivate&) const;
199
QDomNodePrivate* item(int index);
203
QDomNodePrivate* node_impl;
206
QList<QDomNodePrivate*> list;
210
class QDomNamedNodeMapPrivate
213
QDomNamedNodeMapPrivate(QDomNodePrivate*);
214
~QDomNamedNodeMapPrivate();
216
QDomNodePrivate* namedItem(const QString& name) const;
217
QDomNodePrivate* namedItemNS(const QString& nsURI, const QString& localName) const;
218
QDomNodePrivate* setNamedItem(QDomNodePrivate* arg);
219
QDomNodePrivate* setNamedItemNS(QDomNodePrivate* arg);
220
QDomNodePrivate* removeNamedItem(const QString& name);
221
QDomNodePrivate* item(int index) const;
223
bool contains(const QString& name) const;
224
bool containsNS(const QString& nsURI, const QString & localName) const;
227
* Remove all children from the map.
230
bool isReadOnly() { return readonly; }
231
void setReadOnly(bool r) { readonly = r; }
232
bool isAppendToParent() { return appendToParent; }
234
* If true, then the node will redirect insert/remove calls
235
* to its parent by calling QDomNodePrivate::appendChild or removeChild.
236
* In addition the map wont increase or decrease the reference count
237
* of the nodes it contains.
239
* By default this value is false and the map will handle reference counting
242
void setAppendToParent(bool b) { appendToParent = b; }
245
* Creates a copy of the map. It is a deep copy
246
* that means that all children are cloned.
248
QDomNamedNodeMapPrivate* clone(QDomNodePrivate* parent);
252
QHash<QString, QDomNodePrivate *> map;
253
QDomNodePrivate* parent;
258
class QDomDocumentTypePrivate : public QDomNodePrivate
261
QDomDocumentTypePrivate(QDomDocumentPrivate*, QDomNodePrivate* parent = 0);
262
QDomDocumentTypePrivate(QDomDocumentTypePrivate* n, bool deep);
263
~QDomDocumentTypePrivate();
266
// Reimplemented from QDomNodePrivate
267
QDomNodePrivate* cloneNode(bool deep = true);
268
QDomNodePrivate* insertBefore(QDomNodePrivate* newChild, QDomNodePrivate* refChild);
269
QDomNodePrivate* insertAfter(QDomNodePrivate* newChild, QDomNodePrivate* refChild);
270
QDomNodePrivate* replaceChild(QDomNodePrivate* newChild, QDomNodePrivate* oldChild);
271
QDomNodePrivate* removeChild(QDomNodePrivate* oldChild);
272
QDomNodePrivate* appendChild(QDomNodePrivate* newChild);
274
bool isDocumentType() { return true; }
275
QDomNode::NodeType nodeType() const { return QDomNode::DocumentTypeNode; }
277
void save(QTextStream& s, int, int) const;
280
QDomNamedNodeMapPrivate* entities;
281
QDomNamedNodeMapPrivate* notations;
284
QString internalSubset;
287
class QDomDocumentFragmentPrivate : public QDomNodePrivate
290
QDomDocumentFragmentPrivate(QDomDocumentPrivate*, QDomNodePrivate* parent = 0);
291
QDomDocumentFragmentPrivate(QDomNodePrivate* n, bool deep);
293
// Reimplemented from QDomNodePrivate
294
QDomNodePrivate* cloneNode(bool deep = true);
295
bool isDocumentFragment() { return true; }
296
QDomNode::NodeType nodeType() const { return QDomNode::DocumentFragmentNode; }
299
class QDomCharacterDataPrivate : public QDomNodePrivate
302
QDomCharacterDataPrivate(QDomDocumentPrivate*, QDomNodePrivate* parent, const QString& data);
303
QDomCharacterDataPrivate(QDomCharacterDataPrivate* n, bool deep);
305
uint dataLength() const;
306
QString substringData(unsigned long offset, unsigned long count) const;
307
void appendData(const QString& arg);
308
void insertData(unsigned long offset, const QString& arg);
309
void deleteData(unsigned long offset, unsigned long count);
310
void replaceData(unsigned long offset, unsigned long count, const QString& arg);
312
// Reimplemented from QDomNodePrivate
313
bool isCharacterData() { return true; }
314
QDomNode::NodeType nodeType() const { return QDomNode::CharacterDataNode; }
315
QDomNodePrivate* cloneNode(bool deep = true);
318
class QDomTextPrivate : public QDomCharacterDataPrivate
321
QDomTextPrivate(QDomDocumentPrivate*, QDomNodePrivate* parent, const QString& val);
322
QDomTextPrivate(QDomTextPrivate* n, bool deep);
324
QDomTextPrivate* splitText(int offset);
326
// Reimplemented from QDomNodePrivate
327
QDomNodePrivate* cloneNode(bool deep = true);
328
bool isText() { return true; }
329
QDomNode::NodeType nodeType() const { return QDomNode::TextNode; }
330
void save(QTextStream& s, int, int) const;
333
class QDomAttrPrivate : public QDomNodePrivate
336
QDomAttrPrivate(QDomDocumentPrivate*, QDomNodePrivate*, const QString& name);
337
QDomAttrPrivate(QDomDocumentPrivate*, QDomNodePrivate*, const QString& nsURI, const QString& qName);
338
QDomAttrPrivate(QDomAttrPrivate* n, bool deep);
340
bool specified() const;
342
// Reimplemented from QDomNodePrivate
343
void setNodeValue(const QString& v);
344
QDomNodePrivate* cloneNode(bool deep = true);
345
bool isAttr() { return true; }
346
QDomNode::NodeType nodeType() const { return QDomNode::AttributeNode; }
347
void save(QTextStream& s, int, int) const;
353
class QDomElementPrivate : public QDomNodePrivate
356
QDomElementPrivate(QDomDocumentPrivate*, QDomNodePrivate* parent, const QString& name);
357
QDomElementPrivate(QDomDocumentPrivate*, QDomNodePrivate* parent, const QString& nsURI, const QString& qName);
358
QDomElementPrivate(QDomElementPrivate* n, bool deep);
359
~QDomElementPrivate();
361
QString attribute(const QString& name, const QString& defValue) const;
362
QString attributeNS(const QString& nsURI, const QString& localName, const QString& defValue) const;
363
void setAttribute(const QString& name, const QString& value);
364
void setAttributeNS(const QString& nsURI, const QString& qName, const QString& newValue);
365
void removeAttribute(const QString& name);
366
QDomAttrPrivate* attributeNode(const QString& name);
367
QDomAttrPrivate* attributeNodeNS(const QString& nsURI, const QString& localName);
368
QDomAttrPrivate* setAttributeNode(QDomAttrPrivate* newAttr);
369
QDomAttrPrivate* setAttributeNodeNS(QDomAttrPrivate* newAttr);
370
QDomAttrPrivate* removeAttributeNode(QDomAttrPrivate* oldAttr);
371
bool hasAttribute(const QString& name);
372
bool hasAttributeNS(const QString& nsURI, const QString& localName);
376
// Reimplemented from QDomNodePrivate
377
QDomNamedNodeMapPrivate* attributes() { return m_attr; }
378
bool hasAttributes() { return (m_attr->length() > 0); }
379
bool isElement() { return true; }
380
QDomNode::NodeType nodeType() const { return QDomNode::ElementNode; }
381
QDomNodePrivate* cloneNode(bool deep = true);
382
void save(QTextStream& s, int, int) const;
385
QDomNamedNodeMapPrivate* m_attr;
389
class QDomCommentPrivate : public QDomCharacterDataPrivate
392
QDomCommentPrivate(QDomDocumentPrivate*, QDomNodePrivate* parent, const QString& val);
393
QDomCommentPrivate(QDomCommentPrivate* n, bool deep);
395
// Reimplemented from QDomNodePrivate
396
QDomNodePrivate* cloneNode(bool deep = true);
397
bool isComment() { return true; }
398
QDomNode::NodeType nodeType() const { return QDomNode::CommentNode; }
399
void save(QTextStream& s, int, int) const;
402
class QDomCDATASectionPrivate : public QDomTextPrivate
405
QDomCDATASectionPrivate(QDomDocumentPrivate*, QDomNodePrivate* parent, const QString& val);
406
QDomCDATASectionPrivate(QDomCDATASectionPrivate* n, bool deep);
408
// Reimplemented from QDomNodePrivate
409
QDomNodePrivate* cloneNode(bool deep = true);
410
bool isCDATASection() { return true; }
411
QDomNode::NodeType nodeType() const { return QDomNode::CDATASectionNode; }
412
void save(QTextStream& s, int, int) const;
415
class QDomNotationPrivate : public QDomNodePrivate
418
QDomNotationPrivate(QDomDocumentPrivate*, QDomNodePrivate* parent, const QString& name,
419
const QString& pub, const QString& sys);
420
QDomNotationPrivate(QDomNotationPrivate* n, bool deep);
422
// Reimplemented from QDomNodePrivate
423
QDomNodePrivate* cloneNode(bool deep = true);
424
bool isNotation() { return true; }
425
QDomNode::NodeType nodeType() const { return QDomNode::NotationNode; }
426
void save(QTextStream& s, int, int) const;
433
class QDomEntityPrivate : public QDomNodePrivate
436
QDomEntityPrivate(QDomDocumentPrivate*, QDomNodePrivate* parent, const QString& name,
437
const QString& pub, const QString& sys, const QString& notation);
438
QDomEntityPrivate(QDomEntityPrivate* n, bool deep);
440
// Reimplemented from QDomNodePrivate
441
QDomNodePrivate* cloneNode(bool deep = true);
442
bool isEntity() { return true; }
443
QDomNode::NodeType nodeType() const { return QDomNode::EntityNode; }
444
void save(QTextStream& s, int, int) const;
449
QString m_notationName;
452
class QDomEntityReferencePrivate : public QDomNodePrivate
455
QDomEntityReferencePrivate(QDomDocumentPrivate*, QDomNodePrivate* parent, const QString& name);
456
QDomEntityReferencePrivate(QDomNodePrivate* n, bool deep);
458
// Reimplemented from QDomNodePrivate
459
QDomNodePrivate* cloneNode(bool deep = true);
460
bool isEntityReference() { return true; }
461
QDomNode::NodeType nodeType() const { return QDomNode::EntityReferenceNode; }
462
void save(QTextStream& s, int, int) const;
465
class QDomProcessingInstructionPrivate : public QDomNodePrivate
468
QDomProcessingInstructionPrivate(QDomDocumentPrivate*, QDomNodePrivate* parent, const QString& target,
469
const QString& data);
470
QDomProcessingInstructionPrivate(QDomProcessingInstructionPrivate* n, bool deep);
472
// Reimplemented from QDomNodePrivate
473
QDomNodePrivate* cloneNode(bool deep = true);
474
bool isProcessingInstruction() { return true; }
475
QDomNode::NodeType nodeType() const { return QDomNode::ProcessingInstructionNode; }
476
void save(QTextStream& s, int, int) const;
479
class QDomDocumentPrivate : public QDomNodePrivate
482
QDomDocumentPrivate();
483
QDomDocumentPrivate(const QString& name);
484
QDomDocumentPrivate(QDomDocumentTypePrivate* dt);
485
QDomDocumentPrivate(QDomDocumentPrivate* n, bool deep);
486
~QDomDocumentPrivate();
488
bool setContent(QXmlInputSource *source, bool namespaceProcessing, QString *errorMsg, int *errorLine, int *errorColumn);
489
bool setContent(QXmlInputSource *source, QXmlReader *reader, QString *errorMsg, int *errorLine, int *errorColumn);
492
QDomDocumentTypePrivate* doctype() { return type; };
493
QDomImplementationPrivate* implementation() { return impl; };
494
QDomElementPrivate* documentElement();
497
QDomElementPrivate* createElement(const QString& tagName);
498
QDomElementPrivate* createElementNS(const QString& nsURI, const QString& qName);
499
QDomDocumentFragmentPrivate* createDocumentFragment();
500
QDomTextPrivate* createTextNode(const QString& data);
501
QDomCommentPrivate* createComment(const QString& data);
502
QDomCDATASectionPrivate* createCDATASection(const QString& data);
503
QDomProcessingInstructionPrivate* createProcessingInstruction(const QString& target, const QString& data);
504
QDomAttrPrivate* createAttribute(const QString& name);
505
QDomAttrPrivate* createAttributeNS(const QString& nsURI, const QString& qName);
506
QDomEntityReferencePrivate* createEntityReference(const QString& name);
508
QDomNodePrivate* importNode(const QDomNodePrivate* importedNode, bool deep);
510
// Reimplemented from QDomNodePrivate
511
QDomNodePrivate* cloneNode(bool deep = true);
512
bool isDocument() { return true; }
513
QDomNode::NodeType nodeType() const { return QDomNode::DocumentNode; }
515
void save(QTextStream&, int, int) const;
518
QDomImplementationPrivate* impl;
519
QDomDocumentTypePrivate* type;
522
/**************************************************************
526
**************************************************************/
528
class QDomHandler : public QXmlDefaultHandler
531
QDomHandler(QDomDocumentPrivate* d, bool namespaceProcessing);
536
bool startElement(const QString& nsURI, const QString& localName, const QString& qName, const QXmlAttributes& atts);
537
bool endElement(const QString& nsURI, const QString& localName, const QString& qName);
538
bool characters(const QString& ch);
539
bool processingInstruction(const QString& target, const QString& data);
540
bool skippedEntity(const QString& name);
543
bool fatalError(const QXmlParseException& exception);
548
bool startEntity(const QString &);
549
bool endEntity(const QString &);
550
bool startDTD(const QString& name, const QString& publicId, const QString& systemId);
551
bool comment(const QString& ch);
554
bool externalEntityDecl(const QString &name, const QString &publicId, const QString &systemId) ;
557
bool notationDecl(const QString & name, const QString & publicId, const QString & systemId);
558
bool unparsedEntityDecl(const QString &name, const QString &publicId, const QString &systemId, const QString ¬ationName) ;
565
QDomDocumentPrivate *doc;
566
QDomNodePrivate *node;
572
/**************************************************************
574
* QDomImplementationPrivate
576
**************************************************************/
578
QDomImplementationPrivate* QDomImplementationPrivate::clone()
580
QDomImplementationPrivate* p = new QDomImplementationPrivate;
581
// We are not interested in this node
586
/**************************************************************
590
**************************************************************/
593
\class QDomImplementation
595
\brief The QDomImplementation class provides information about the
596
features of the DOM implementation.
601
This class describes the features that are supported by the DOM
602
implementation. Currently the XML subset of DOM Level 1 and DOM
603
Level 2 Core are supported.
605
Normally you will use the function QDomDocument::implementation()
606
to get the implementation object.
608
You can create a new document type with createDocumentType() and a
609
new document with createDocument().
611
For further information about the Document Object Model see
612
\l{http://www.w3.org/TR/REC-DOM-Level-1/}{Level 1} and
613
\l{http://www.w3.org/TR/DOM-Level-2-Core/}{Level 2 Core}. For a more
614
general introduction of the DOM implementation see the QDomDocument
621
Constructs a QDomImplementation object.
623
QDomImplementation::QDomImplementation()
629
Constructs a copy of \a x.
631
QDomImplementation::QDomImplementation(const QDomImplementation &x)
638
QDomImplementation::QDomImplementation(QDomImplementationPrivate *p)
640
// We want to be co-owners, so increase the reference count
647
Assigns \a x to this DOM implementation.
649
QDomImplementation& QDomImplementation::operator=(const QDomImplementation &x)
651
QDomImplementationPrivate *p = x.impl;
654
p = qAtomicSetPtr(&impl, p);
655
if (p && !p->ref.deref())
661
Returns true if \a x and this DOM implementation object were
662
created from the same QDomDocument; otherwise returns false.
664
bool QDomImplementation::operator==(const QDomImplementation &x) const
666
return (impl == x.impl);
670
Returns true if \a x and this DOM implementation object were
671
created from different QDomDocuments; otherwise returns false.
673
bool QDomImplementation::operator!=(const QDomImplementation &x) const
675
return (impl != x.impl);
679
Destroys the object and frees its resources.
681
QDomImplementation::~QDomImplementation()
683
if (impl && !impl->ref.deref())
688
The function returns true if QDom implements the requested \a
689
version of a \a feature; otherwise returns false.
691
The currently supported features and their versions:
693
\header \i Feature \i Version
697
bool QDomImplementation::hasFeature(const QString& feature, const QString& version) const
699
if (feature == "XML") {
700
if (version.isEmpty() || version == "1.0") {
704
// ### add DOM level 2 features
709
Creates a document type node for the name \a qName.
711
\a publicId specifies the public identifier of the external
712
subset. If you specify an empty string (QString()) as the \a
713
publicId, this means that the document type has no public
716
\a systemId specifies the system identifier of the external
717
subset. If you specify an empty string as the \a systemId, this
718
means that the document type has no system identifier.
720
Since you cannot have a public identifier without a system
721
identifier, the public identifier is set to an empty string if
722
there is no system identifier.
724
DOM level 2 does not support any other document type declaration
727
The only way you can use a document type that was created this
728
way, is in combination with the createDocument() function to
729
create a QDomDocument with this document type.
733
QDomDocumentType QDomImplementation::createDocumentType(const QString& qName, const QString& publicId, const QString& systemId)
735
QDomDocumentTypePrivate *dt = new QDomDocumentTypePrivate(0);
737
if (systemId.isNull()) {
738
dt->publicId.clear();
739
dt->systemId.clear();
741
dt->publicId = publicId;
742
dt->systemId = systemId;
744
return QDomDocumentType(dt);
748
Creates a DOM document with the document type \a doctype. This
749
function also adds a root element node with the qualified name \a
750
qName and the namespace URI \a nsURI.
752
QDomDocument QDomImplementation::createDocument(const QString& nsURI, const QString& qName, const QDomDocumentType& doctype)
754
QDomDocument doc(doctype);
755
QDomElement root = doc.createElementNS(nsURI, qName);
756
doc.appendChild(root);
761
Returns false if the object was created by
762
QDomDocument::implementation(); otherwise returns true.
764
bool QDomImplementation::isNull()
769
/**************************************************************
771
* QDomNodeListPrivate
773
**************************************************************/
775
QDomNodeListPrivate::QDomNodeListPrivate(QDomNodePrivate *n_impl)
780
node_impl->ref.ref();
784
QDomNodeListPrivate::QDomNodeListPrivate(QDomNodePrivate *n_impl, const QString &name)
789
node_impl->ref.ref();
794
QDomNodeListPrivate::QDomNodeListPrivate(QDomNodePrivate *n_impl, const QString &_nsURI, const QString &localName)
799
node_impl->ref.ref();
805
QDomNodeListPrivate::~QDomNodeListPrivate()
807
if (node_impl && !node_impl->ref.deref())
811
bool QDomNodeListPrivate::operator==(const QDomNodeListPrivate &other) const
813
return (node_impl == other.node_impl) && (tagname == other.tagname);
816
bool QDomNodeListPrivate::operator!=(const QDomNodeListPrivate &other) const
818
return (node_impl != other.node_impl) || (tagname != other.tagname);
821
void QDomNodeListPrivate::createList()
825
timestamp = qt_nodeListTime;
826
QDomNodePrivate* p = node_impl->first;
829
if (tagname.isNull()) {
834
} else if (nsURI.isNull()) {
835
while (p && p != node_impl) {
836
if (p->isElement() && p->nodeName() == tagname) {
845
while (p && p != node_impl && !p->next)
847
if (p && p != node_impl)
852
while (p && p != node_impl) {
853
if (p->isElement() && p->name==tagname && p->namespaceURI==nsURI) {
862
while (p && p != node_impl && !p->next)
864
if (p && p != node_impl)
871
QDomNodePrivate* QDomNodeListPrivate::item(int index)
875
if (timestamp < qt_nodeListTime)
877
return list.at(index);
880
uint QDomNodeListPrivate::length() const
884
if (timestamp < qt_nodeListTime) {
885
QDomNodeListPrivate *that = (QDomNodeListPrivate*)this;
891
/**************************************************************
895
**************************************************************/
900
\brief The QDomNodeList class is a list of QDomNode objects.
905
Lists can be obtained by QDomDocument::elementsByTagName() and
906
QDomNode::childNodes(). The Document Object Model (DOM) requires
907
these lists to be "live": whenever you change the underlying
908
document, the contents of the list will get updated.
910
You can get a particular node from the list with item(). The
911
number of items in the list is returned by count() (and by
914
For further information about the Document Object Model see
915
\l{http://www.w3.org/TR/REC-DOM-Level-1/}{Level 1} and
916
\l{http://www.w3.org/TR/DOM-Level-2-Core/}{Level 2 Core}.
917
For a more general introduction of the DOM implementation see the
918
QDomDocument documentation.
920
\sa QDomNode::childNodes() QDomDocument::elementsByTagName()
924
Creates an empty node list.
926
QDomNodeList::QDomNodeList()
931
QDomNodeList::QDomNodeList(QDomNodeListPrivate* p)
937
Constructs a copy of \a n.
939
QDomNodeList::QDomNodeList(const QDomNodeList& n)
947
Assigns \a n to this node list.
949
QDomNodeList& QDomNodeList::operator=(const QDomNodeList &n)
951
QDomNodeListPrivate *x = n.impl;
954
x = qAtomicSetPtr(&impl, x);
955
if (x && !x->ref.deref())
961
Returns true if the node list \a n and this node list are equal;
962
otherwise returns false.
964
bool QDomNodeList::operator==(const QDomNodeList &n) const
968
if (!impl || !n.impl)
970
return (*impl == *n.impl);
974
Returns true the node list \a n and this node list are not equal;
975
otherwise returns false.
977
bool QDomNodeList::operator!=(const QDomNodeList &n) const
979
return !operator==(n);
983
Destroys the object and frees its resources.
985
QDomNodeList::~QDomNodeList()
987
if (impl && !impl->ref.deref())
992
Returns the node at position \a index.
994
If \a index is negative or if \a index >= length() then a null
995
node is returned (i.e. a node for which QDomNode::isNull() returns
1000
QDomNode QDomNodeList::item(int index) const
1005
return QDomNode(impl->item(index));
1009
Returns the number of nodes in the list.
1011
This function is the same as count().
1013
uint QDomNodeList::length() const
1017
return impl->length();
1021
\fn uint QDomNodeList::count() const
1023
Returns the number of nodes in the list.
1025
This function is the same as length().
1029
/**************************************************************
1033
**************************************************************/
1035
inline void QDomNodePrivate::setOwnerDocument(QDomDocumentPrivate *doc)
1041
QDomNodePrivate::QDomNodePrivate(QDomDocumentPrivate *doc, QDomNodePrivate *par)
1047
setOwnerDocument(doc);
1052
createdWithDom1Interface = true;
1055
QDomNodePrivate::QDomNodePrivate(QDomNodePrivate *n, bool deep)
1058
setOwnerDocument(n->ownerDocument());
1067
namespaceURI = n->namespaceURI;
1068
createdWithDom1Interface = n->createdWithDom1Interface;
1073
for (QDomNodePrivate* x = n->first; x; x = x->next)
1074
appendChild(x->cloneNode(true));
1077
QDomNodePrivate::~QDomNodePrivate()
1079
QDomNodePrivate* p = first;
1084
if (!p->ref.deref())
1094
void QDomNodePrivate::clear()
1096
QDomNodePrivate* p = first;
1101
if (!p->ref.deref())
1109
QDomNodePrivate* QDomNodePrivate::namedItem(const QString &n)
1111
QDomNodePrivate* p = first;
1113
if (p->nodeName() == n)
1121
QDomNodePrivate* QDomNodePrivate::insertBefore(QDomNodePrivate* newChild, QDomNodePrivate* refChild)
1128
if (newChild == refChild)
1132
if (refChild && refChild->parent() != this)
1135
// "mark lists as dirty"
1138
// Special handling for inserting a fragment. We just insert
1139
// all elements of the fragment instead of the fragment itself.
1140
if (newChild->isDocumentFragment()) {
1141
// Fragment is empty ?
1142
if (newChild->first == 0)
1146
QDomNodePrivate* n = newChild->first;
1152
// Insert at the beginning ?
1153
if (!refChild || refChild->prev == 0) {
1155
first->prev = newChild->last;
1156
newChild->last->next = first;
1158
last = newChild->last;
1159
first = newChild->first;
1161
// Insert in the middle
1162
newChild->last->next = refChild;
1163
newChild->first->prev = refChild->prev;
1164
refChild->prev->next = newChild->first;
1165
refChild->prev = newChild->last;
1168
// No need to increase the reference since QDomDocumentFragment
1169
// does not decrease the reference.
1171
// Remove the nodes from the fragment
1172
newChild->first = 0;
1177
// No more errors can occur now, so we take
1178
// ownership of the node.
1179
newChild->ref.ref();
1181
if (newChild->parent())
1182
newChild->parent()->removeChild(newChild);
1184
newChild->setParent(this);
1188
first->prev = newChild;
1189
newChild->next = first;
1196
if (refChild->prev == 0) {
1198
first->prev = newChild;
1199
newChild->next = first;
1206
newChild->next = refChild;
1207
newChild->prev = refChild->prev;
1208
refChild->prev->next = newChild;
1209
refChild->prev = newChild;
1214
QDomNodePrivate* QDomNodePrivate::insertAfter(QDomNodePrivate* newChild, QDomNodePrivate* refChild)
1221
if (newChild == refChild)
1225
if (refChild && refChild->parent() != this)
1228
// "mark lists as dirty"
1231
// Special handling for inserting a fragment. We just insert
1232
// all elements of the fragment instead of the fragment itself.
1233
if (newChild->isDocumentFragment()) {
1234
// Fragment is empty ?
1235
if (newChild->first == 0)
1239
QDomNodePrivate* n = newChild->first;
1245
// Insert at the end
1246
if (!refChild || refChild->next == 0) {
1248
last->next = newChild->first;
1249
newChild->first->prev = last;
1251
first = newChild->first;
1252
last = newChild->last;
1253
} else { // Insert in the middle
1254
newChild->first->prev = refChild;
1255
newChild->last->next = refChild->next;
1256
refChild->next->prev = newChild->last;
1257
refChild->next = newChild->first;
1260
// No need to increase the reference since QDomDocumentFragment
1261
// does not decrease the reference.
1263
// Remove the nodes from the fragment
1264
newChild->first = 0;
1269
// Release new node from its current parent
1270
if (newChild->parent())
1271
newChild->parent()->removeChild(newChild);
1273
// No more errors can occur now, so we take
1274
// ownership of the node
1275
newChild->ref.ref();
1277
newChild->setParent(this);
1279
// Insert at the end
1282
last->next = newChild;
1283
newChild->prev = last;
1290
if (refChild->next == 0) {
1292
last->next = newChild;
1293
newChild->prev = last;
1300
newChild->prev = refChild;
1301
newChild->next = refChild->next;
1302
refChild->next->prev = newChild;
1303
refChild->next = newChild;
1308
QDomNodePrivate* QDomNodePrivate::replaceChild(QDomNodePrivate* newChild, QDomNodePrivate* oldChild)
1310
if (oldChild->parent() != this)
1312
if (!newChild || !oldChild)
1314
if (newChild == oldChild)
1317
// mark lists as dirty
1320
// Special handling for inserting a fragment. We just insert
1321
// all elements of the fragment instead of the fragment itself.
1322
if (newChild->isDocumentFragment()) {
1323
// Fragment is empty ?
1324
if (newChild->first == 0)
1328
QDomNodePrivate* n = newChild->first;
1336
oldChild->next->prev = newChild->last;
1338
oldChild->prev->next = newChild->first;
1340
newChild->last->next = oldChild->next;
1341
newChild->first->prev = oldChild->prev;
1343
if (first == oldChild)
1344
first = newChild->first;
1345
if (last == oldChild)
1346
last = newChild->last;
1348
oldChild->setNoParent();
1352
// No need to increase the reference since QDomDocumentFragment
1353
// does not decrease the reference.
1355
// Remove the nodes from the fragment
1356
newChild->first = 0;
1359
// We are no longer interested in the old node
1361
oldChild->ref.deref();
1366
// No more errors can occur now, so we take
1367
// ownership of the node
1368
newChild->ref.ref();
1370
// Release new node from its current parent
1371
if (newChild->parent())
1372
newChild->parent()->removeChild(newChild);
1374
newChild->setParent(this);
1377
oldChild->next->prev = newChild;
1379
oldChild->prev->next = newChild;
1381
newChild->next = oldChild->next;
1382
newChild->prev = oldChild->prev;
1384
if (first == oldChild)
1386
if (last == oldChild)
1389
oldChild->setNoParent();
1393
// We are no longer interested in the old node
1395
oldChild->ref.deref();
1400
QDomNodePrivate* QDomNodePrivate::removeChild(QDomNodePrivate* oldChild)
1403
if (oldChild->parent() != this)
1406
// "mark lists as dirty"
1409
// Perhaps oldChild was just created with "createElement" or that. In this case
1410
// its parent is QDomDocument but it is not part of the documents child list.
1411
if (oldChild->next == 0 && oldChild->prev == 0 && first != oldChild)
1415
oldChild->next->prev = oldChild->prev;
1417
oldChild->prev->next = oldChild->next;
1419
if (last == oldChild)
1420
last = oldChild->prev;
1421
if (first == oldChild)
1422
first = oldChild->next;
1424
oldChild->setNoParent();
1428
// We are no longer interested in the old node
1430
oldChild->ref.deref();
1435
QDomNodePrivate* QDomNodePrivate::appendChild(QDomNodePrivate* newChild)
1437
// No reference manipulation needed. Done in insertAfter.
1438
return insertAfter(newChild, 0);
1441
QDomDocumentPrivate* QDomNodePrivate::ownerDocument()
1443
QDomNodePrivate* p = this;
1444
while (p && !p->isDocument()) {
1446
return (QDomDocumentPrivate*)p->ownerNode;
1450
return (QDomDocumentPrivate*)p;
1453
QDomNodePrivate* QDomNodePrivate::cloneNode(bool deep)
1455
QDomNodePrivate* p = new QDomNodePrivate(this, deep);
1456
// We are not interested in this node
1461
static void qNormalizeNode(QDomNodePrivate* n)
1463
QDomNodePrivate* p = n->first;
1464
QDomTextPrivate* t = 0;
1469
QDomNodePrivate* tmp = p->next;
1470
t->appendData(p->nodeValue());
1474
t = (QDomTextPrivate*)p;
1483
void QDomNodePrivate::normalize()
1485
// ### This one has moved from QDomElementPrivate to this position. It is
1487
qNormalizeNode(this);
1490
void QDomNodePrivate::save(QTextStream& s, int depth, int indent) const
1492
const QDomNodePrivate* n = first;
1494
n->save(s, depth, indent);
1499
/**************************************************************
1503
**************************************************************/
1505
#define IMPL ((QDomNodePrivate*)impl)
1510
\brief The QDomNode class is the base class for all the nodes in a DOM tree.
1516
Many functions in the DOM return a QDomNode.
1518
You can find out the type of a node using isAttr(),
1519
isCDATASection(), isDocumentFragment(), isDocument(),
1520
isDocumentType(), isElement(), isEntityReference(), isText(),
1521
isEntity(), isNotation(), isProcessingInstruction(),
1522
isCharacterData() and isComment().
1524
A QDomNode can be converted into one of its subclasses using
1525
toAttr(), toCDATASection(), toDocumentFragment(), toDocument(),
1526
toDocumentType(), toElement(), toEntityReference(), toText(),
1527
toEntity(), toNotation(), toProcessingInstruction(),
1528
toCharacterData() or toComment(). You can convert a node to a null
1531
Copies of the QDomNode class share their data using explicit
1532
sharing. This means that modifying one node will change all
1533
copies. This is especially useful in combination with functions
1534
which return a QDomNode, e.g. firstChild(). You can make an
1535
independent (deep) copy of the node with cloneNode().
1537
Nodes are inserted with insertBefore(), insertAfter() or
1538
appendChild(). You can replace one node with another using
1539
replaceChild() and remove a node with removeChild().
1541
To traverse nodes use firstChild() to get a node's first child (if
1542
any), and nextSibling() to traverse. QDomNode also provides
1543
lastChild(), previousSibling() and parentNode(). To find the first
1544
child node with a particular node name use namedItem().
1546
To find out if a node has children use hasChildNodes() and to get
1547
a list of all of a node's children use childNodes().
1549
The node's name and value (the meaning of which varies depending
1550
on its type) is returned by nodeName() and nodeValue()
1551
respectively. The node's type is returned by nodeType(). The
1552
node's value can be set with setNodeValue().
1554
The document to which the node belongs is returned by
1557
Adjacent QDomText nodes can be merged into a single node with
1560
\l QDomElement nodes have attributes which can be retrieved with
1563
QDomElement and QDomAttr nodes can have namespaces which can be
1564
retrieved with namespaceURI(). Their local name is retrieved with
1565
localName(), and their prefix with prefix(). The prefix can be set
1568
You can write the XML representation of the node to a text stream
1571
The following example looks for the first element in an XML document and
1572
prints the names of all the elements that are its direct children.
1575
d.setContent(someXML);
1576
QDomNode n = d.firstChild();
1577
while (!n.isNull()) {
1578
if (n.isElement()) {
1579
QDomElement e = n.toElement();
1580
cout << "Element name: " << e.tagName() << endl;
1583
n = n.nextSibling();
1587
For further information about the Document Object Model see
1588
\l{http://www.w3.org/TR/REC-DOM-Level-1/}{Level 1} and
1589
\l{http://www.w3.org/TR/DOM-Level-2-Core/}{Level 2 Core}.
1590
For a more general introduction of the DOM implementation see the
1591
QDomDocument documentation.
1595
Constructs a \link isNull() null\endlink node.
1597
QDomNode::QDomNode()
1603
Constructs a copy of \a n.
1605
The data of the copy is shared (shallow copy): modifying one node
1606
will also change the other. If you want to make a deep copy, use
1609
QDomNode::QDomNode(const QDomNode &n)
1617
Constructs a new node for the data \a n.
1619
QDomNode::QDomNode(QDomNodePrivate *n)
1627
Assigns a copy of \a n to this DOM node.
1629
The data of the copy is shared (shallow copy): modifying one node
1630
will also change the other. If you want to make a deep copy, use
1633
QDomNode& QDomNode::operator=(const QDomNode &n)
1635
QDomNodePrivate *x = n.impl;
1638
x = qAtomicSetPtr(&impl, x);
1639
if (x && !x->ref.deref())
1645
Returns true if \a n and this DOM node are equal; otherwise
1648
bool QDomNode::operator== (const QDomNode& n) const
1650
return (impl == n.impl);
1654
Returns true if \a n and this DOM node are not equal; otherwise
1657
bool QDomNode::operator!= (const QDomNode& n) const
1659
return (impl != n.impl);
1663
Destroys the object and frees its resources.
1665
QDomNode::~QDomNode()
1667
if (impl && !impl->ref.deref())
1672
Returns the name of the node.
1674
The meaning of the name depends on the subclass:
1676
\header \i Name \i Meaning
1677
\row \i QDomAttr \i The name of the attribute
1678
\row \i QDomCDATASection \i The string "#cdata-section"
1679
\row \i QDomComment \i The string "#comment"
1680
\row \i QDomDocument \i The string "#document"
1681
\row \i QDomDocumentFragment \i The string "#document-fragment"
1682
\row \i QDomDocumentType \i The name of the document type
1683
\row \i QDomElement \i The tag name
1684
\row \i QDomEntity \i The name of the entity
1685
\row \i QDomEntityReference \i The name of the referenced entity
1686
\row \i QDomNotation \i The name of the notation
1687
\row \i QDomProcessingInstruction \i The target of the processing instruction
1688
\row \i QDomText \i The string "#text"
1693
QString QDomNode::nodeName() const
1698
if (!IMPL->prefix.isEmpty())
1699
return IMPL->prefix + ":" + IMPL->name;
1704
Returns the value of the node.
1706
The meaning of the value depends on the subclass:
1708
\header \i Name \i Meaning
1709
\row \i QDomAttr \i The attribute value
1710
\row \i QDomCDATASection \i The content of the CDATA section
1711
\row \i QDomComment \i The comment
1712
\row \i QDomProcessingInstruction \i The data of the processing intruction
1713
\row \i QDomText \i The text
1716
All the other subclasses do not have a node value and will return
1719
\sa setNodeValue() nodeName()
1721
QString QDomNode::nodeValue() const
1729
Sets the node's value to \a v.
1733
void QDomNode::setNodeValue(const QString& v)
1737
IMPL->setNodeValue(v);
1741
\enum QDomNode::NodeType
1743
This enum defines the type of the node:
1745
\value AttributeNode
1747
\value CDATASectionNode
1748
\value EntityReferenceNode
1750
\value ProcessingInstructionNode
1753
\value DocumentTypeNode
1754
\value DocumentFragmentNode
1756
\value BaseNode A QDomNode object, i.e. not a QDomNode subclass.
1757
\value CharacterDataNode
1761
Returns the type of the node.
1763
\sa toAttr(), toCDATASection(), toDocumentFragment(),
1764
toDocument() toDocumentType(), toElement(), toEntityReference(),
1765
toText(), toEntity() toNotation(), toProcessingInstruction(),
1766
toCharacterData(), toComment()
1768
QDomNode::NodeType QDomNode::nodeType() const
1771
return QDomNode::BaseNode;
1772
return IMPL->nodeType();
1776
Returns the parent node. If this node has no parent, a null node
1777
is returned (i.e. a node for which isNull() returns true).
1779
QDomNode QDomNode::parentNode() const
1783
return QDomNode(IMPL->parent());
1787
Returns a list of all direct child nodes.
1789
Most often you will call this function on a QDomElement object.
1791
For example, if the XML document looks like this:
1795
<p>Hello <b>you</b></p>
1798
Then the list of child nodes for the "body"-element will contain
1799
the node created by the <h1> tag and the node created by the
1802
The nodes in the list are not copied; so changing the nodes in the
1803
list will also change the children of this node.
1805
\sa firstChild() lastChild()
1807
QDomNodeList QDomNode::childNodes() const
1810
return QDomNodeList();
1811
return QDomNodeList(new QDomNodeListPrivate(impl));
1815
Returns the first child of the node. If there is no child node, a
1816
\link isNull() null node\endlink is returned. Changing the
1817
returned node will also change the node in the document tree.
1819
\sa lastChild() childNodes()
1821
QDomNode QDomNode::firstChild() const
1825
return QDomNode(IMPL->first);
1829
Returns the last child of the node. If there is no child node, a
1830
\link isNull() null node\endlink is returned. Changing the
1831
returned node will also change the node in the document tree.
1833
\sa firstChild() childNodes()
1835
QDomNode QDomNode::lastChild() const
1839
return QDomNode(IMPL->last);
1843
Returns the previous sibling in the document tree. Changing the
1844
returned node will also change the node in the document tree.
1846
For example, if you have XML like this:
1850
<h2>Next heading</h2>
1852
and this QDomNode represents the <p> tag, previousSibling()
1853
will return the node representing the <h1> tag.
1857
QDomNode QDomNode::previousSibling() const
1861
return QDomNode(IMPL->prev);
1865
Returns the next sibling in the document tree. Changing the
1866
returned node will also change the node in the document tree.
1868
If you have XML like this:
1872
<h2>Next heading</h2>
1874
and this QDomNode represents the <p> tag, nextSibling() will
1875
return the node representing the <h2> tag.
1877
\sa previousSibling()
1879
QDomNode QDomNode::nextSibling() const
1883
return QDomNode(IMPL->next);
1887
// ###### don't think this is part of the DOM and
1889
Returns a named node map of all attributes. Attributes are only
1890
provided for \l{QDomElement}s.
1892
Changing the attributes in the map will also change the attributes
1895
QDomNamedNodeMap QDomNode::attributes() const
1897
if (!impl || !impl->isElement())
1898
return QDomNamedNodeMap();
1900
return QDomNamedNodeMap(static_cast<QDomElementPrivate *>(impl)->attributes());
1904
Returns the document to which this node belongs.
1906
QDomDocument QDomNode::ownerDocument() const
1909
return QDomDocument();
1910
return QDomDocument(IMPL->ownerDocument());
1914
Creates a deep (not shallow) copy of the QDomNode.
1916
If \a deep is true, then the cloning is done recursively which
1917
means that all the node's children are deep copied too. If \a deep
1918
is false only the node itself is copied and the copy will have no
1921
QDomNode QDomNode::cloneNode(bool deep) const
1925
return QDomNode(IMPL->cloneNode(deep));
1929
Calling normalize() on an element converts all its children into a
1930
standard form. This means that adjacent QDomText objects will be
1931
merged into a single text object (QDomCDATASection nodes are not
1934
void QDomNode::normalize()
1942
Returns true if the DOM implementation implements the feature \a
1943
feature and this feature is supported by this node in the version
1944
\a version; otherwise returns false.
1946
\sa QDomImplementation::hasFeature()
1948
bool QDomNode::isSupported(const QString& feature, const QString& version) const
1950
QDomImplementation i;
1951
return i.hasFeature(feature, version);
1955
Returns the namespace URI of this node or an empty string if the
1956
node has no namespace URI.
1958
Only nodes of type \link QDomNode::NodeType ElementNode\endlink or
1959
\link QDomNode::NodeType AttributeNode\endlink can have
1960
namespaces. A namespace URI must be specified at creation time and
1961
cannot be changed later.
1963
\sa prefix() localName() QDomDocument::createElementNS()
1964
QDomDocument::createAttributeNS()
1966
QString QDomNode::namespaceURI() const
1970
return IMPL->namespaceURI;
1974
Returns the namespace prefix of the node or an empty string if the
1975
node has no namespace prefix.
1977
Only nodes of type \link QDomNode::NodeType ElementNode\endlink or
1978
\link QDomNode::NodeType AttributeNode\endlink can have
1979
namespaces. A namespace prefix must be specified at creation time.
1980
If a node was created with a namespace prefix, you can change it
1981
later with setPrefix().
1983
If you create an element or attribute with
1984
QDomDocument::createElement() or QDomDocument::createAttribute(),
1985
the prefix will be an empty string. If you use
1986
QDomDocument::createElementNS() or
1987
QDomDocument::createAttributeNS() instead, the prefix will not be
1988
an empty string; but it might be an empty string if the name does
1991
\sa setPrefix() localName() namespaceURI()
1992
QDomDocument::createElementNS() QDomDocument::createAttributeNS()
1994
QString QDomNode::prefix() const
1998
return IMPL->prefix;
2002
If the node has a namespace prefix, this function changes the
2003
namespace prefix of the node to \a pre. Otherwise this function
2006
Only nodes of type \link QDomNode::NodeType ElementNode\endlink or
2007
\link QDomNode::NodeType AttributeNode\endlink can have
2008
namespaces. A namespace prefix must have be specified at creation
2009
time; it is not possible to add a namespace prefix afterwards.
2011
\sa prefix() localName() namespaceURI()
2012
QDomDocument::createElementNS() QDomDocument::createAttributeNS()
2014
void QDomNode::setPrefix(const QString& pre)
2016
if (!impl || IMPL->prefix.isNull())
2018
if (isAttr() || isElement())
2023
If the node uses namespaces, this function returns the local name
2024
of the node; otherwise it returns an empty string.
2026
Only nodes of type \link QDomNode::NodeType ElementNode\endlink or
2027
\link QDomNode::NodeType AttributeNode\endlink can have
2028
namespaces. A namespace must have been specified at creation time;
2029
it is not possible to add a namespace afterwards.
2031
\sa prefix() namespaceURI() QDomDocument::createElementNS()
2032
QDomDocument::createAttributeNS()
2034
QString QDomNode::localName() const
2036
if (!impl || IMPL->createdWithDom1Interface)
2042
Returns true if the node has attributes; otherwise returns false.
2046
bool QDomNode::hasAttributes() const
2048
if (!impl || !impl->isElement())
2050
return static_cast<QDomElementPrivate *>(impl)->hasAttributes();
2054
Inserts the node \a newChild before the child node \a refChild.
2055
\a refChild must be a direct child of this node. If \a refChild is
2056
\link isNull() null\endlink then \a newChild is inserted as the
2059
If \a newChild is the child of another node, it is reparented to
2060
this node. If \a newChild is a child of this node, then its
2061
position in the list of children is changed.
2063
If \a newChild is a QDomDocumentFragment, then the children of the
2064
fragment are removed from the fragment and inserted before \a
2067
Returns a new reference to \a newChild on success or a \link
2068
isNull() null node\endlink on failure.
2070
\sa insertAfter() replaceChild() removeChild() appendChild()
2072
QDomNode QDomNode::insertBefore(const QDomNode& newChild, const QDomNode& refChild)
2076
return QDomNode(IMPL->insertBefore(newChild.impl, refChild.impl));
2080
Inserts the node \a newChild after the child node \a refChild. \a
2081
refChild must be a direct child of this node. If \a refChild is
2082
\link isNull() null\endlink then \a newChild is appended as this
2085
If \a newChild is the child of another node, it is reparented to
2086
this node. If \a newChild is a child of this node, then its
2087
position in the list of children is changed.
2089
If \a newChild is a QDomDocumentFragment, then the children of the
2090
fragment are removed from the fragment and inserted after \a
2093
Returns a new reference to \a newChild on success or a \link
2094
isNull() null node\endlink on failure.
2096
\sa insertBefore() replaceChild() removeChild() appendChild()
2098
QDomNode QDomNode::insertAfter(const QDomNode& newChild, const QDomNode& refChild)
2102
return QDomNode(IMPL->insertAfter(newChild.impl, refChild.impl));
2106
Replaces \a oldChild with \a newChild. \a oldChild must be a
2107
direct child of this node.
2109
If \a newChild is the child of another node, it is reparented to
2110
this node. If \a newChild is a child of this node, then its
2111
position in the list of children is changed.
2113
If \a newChild is a QDomDocumentFragment, then \a oldChild is
2114
replaced by all of the children of the fragment.
2116
Returns a new reference to \a oldChild on success or a \link
2117
isNull() null node\endlink an failure.
2119
\sa insertBefore() insertAfter() removeChild() appendChild()
2121
QDomNode QDomNode::replaceChild(const QDomNode& newChild, const QDomNode& oldChild)
2123
if (!impl || !newChild.impl || !oldChild.impl)
2125
return QDomNode(IMPL->replaceChild(newChild.impl, oldChild.impl));
2129
Removes \a oldChild from the list of children. \a oldChild must be
2130
a direct child of this node.
2132
Returns a new reference to \a oldChild on success or a \link
2133
isNull() null node\endlink on failure.
2135
\sa insertBefore() insertAfter() replaceChild() appendChild()
2137
QDomNode QDomNode::removeChild(const QDomNode& oldChild)
2142
if (oldChild.isNull())
2145
return QDomNode(IMPL->removeChild(oldChild.impl));
2149
Appends \a newChild as the node's last child.
2151
If \a newChild is the child of another node, it is reparented to
2152
this node. If \a newChild is a child of this node, then its
2153
position in the list of children is changed.
2155
If \a newChild is a QDomDocumentFragment, then the children of the
2156
fragment are removed from the fragment and appended.
2158
Returns a new reference to \a newChild.
2160
\sa insertBefore() insertAfter() replaceChild() removeChild()
2162
QDomNode QDomNode::appendChild(const QDomNode& newChild)
2166
return QDomNode(IMPL->appendChild(newChild.impl));
2170
Returns true if the node has one or more children; otherwise
2173
bool QDomNode::hasChildNodes() const
2177
return IMPL->first != 0;
2181
Returns true if this node is null (i.e. if it has no type or
2182
contents); otherwise returns false.
2184
bool QDomNode::isNull() const
2190
Converts the node into a null node; if it was not a null node
2191
before, its type and contents are deleted.
2195
void QDomNode::clear()
2197
if (impl && !impl->ref.deref())
2203
Returns the first direct child node for which nodeName() equals \a
2206
If no such direct child exists, a \link isNull() null node\endlink
2211
QDomNode QDomNode::namedItem(const QString& name) const
2215
return QDomNode(impl->namedItem(name));
2219
Writes the XML representation of the node and all its children to
2220
the stream \a str. This function uses \a indent as the amount of
2221
space to indent the node.
2223
void QDomNode::save(QTextStream& str, int indent) const
2226
IMPL->save(str, 1, indent);
2232
Writes the XML representation of the node \a node and all its
2233
children to the stream \a str.
2235
QTextStream& operator<<(QTextStream& str, const QDomNode& node)
2243
Returns true if the node is an attribute; otherwise returns false.
2245
If this function returns true, it does not imply that this object
2246
is a QDomAttribute; you can get the QDomAttribute with
2251
bool QDomNode::isAttr() const
2254
return impl->isAttr();
2259
Returns true if the node is a CDATA section; otherwise returns
2262
If this function returns true, it does not imply that this object
2263
is a QDomCDATASection; you can get the QDomCDATASection with
2266
\sa toCDATASection()
2268
bool QDomNode::isCDATASection() const
2271
return impl->isCDATASection();
2276
Returns true if the node is a document fragment; otherwise returns
2279
If this function returns true, it does not imply that this object
2280
is a QDomDocumentFragment; you can get the QDomDocumentFragment
2281
with toDocumentFragment().
2283
\sa toDocumentFragment()
2285
bool QDomNode::isDocumentFragment() const
2288
return impl->isDocumentFragment();
2293
Returns true if the node is a document; otherwise returns false.
2295
If this function returns true, it does not imply that this object
2296
is a QDomDocument; you can get the QDomDocument with toDocument().
2300
bool QDomNode::isDocument() const
2303
return impl->isDocument();
2308
Returns true if the node is a document type; otherwise returns
2311
If this function returns true, it does not imply that this object
2312
is a QDomDocumentType; you can get the QDomDocumentType with
2315
\sa toDocumentType()
2317
bool QDomNode::isDocumentType() const
2320
return impl->isDocumentType();
2325
Returns true if the node is an element; otherwise returns false.
2327
If this function returns true, it does not imply that this object
2328
is a QDomElement; you can get the QDomElement with toElement().
2332
bool QDomNode::isElement() const
2335
return impl->isElement();
2340
Returns true if the node is an entity reference; otherwise returns
2343
If this function returns true, it does not imply that this object
2344
is a QDomEntityReference; you can get the QDomEntityReference with
2345
toEntityReference().
2347
\sa toEntityReference()
2349
bool QDomNode::isEntityReference() const
2352
return impl->isEntityReference();
2357
Returns true if the node is a text node; otherwise returns false.
2359
If this function returns true, it does not imply that this object
2360
is a QDomText; you can get the QDomText with toText().
2364
bool QDomNode::isText() const
2367
return impl->isText();
2372
Returns true if the node is an entity; otherwise returns false.
2374
If this function returns true, it does not imply that this object
2375
is a QDomEntity; you can get the QDomEntity with toEntity().
2379
bool QDomNode::isEntity() const
2382
return impl->isEntity();
2387
Returns true if the node is a notation; otherwise returns false.
2389
If this function returns true, it does not imply that this object
2390
is a QDomNotation; you can get the QDomNotation with toNotation().
2394
bool QDomNode::isNotation() const
2397
return impl->isNotation();
2402
Returns true if the node is a processing instruction; otherwise
2405
If this function returns true, it does not imply that this object
2406
is a QDomProcessingInstruction; you can get the
2407
QProcessingInstruction with toProcessingInstruction().
2409
\sa toProcessingInstruction()
2411
bool QDomNode::isProcessingInstruction() const
2414
return impl->isProcessingInstruction();
2419
Returns true if the node is a character data node; otherwise
2422
If this function returns true, it does not imply that this object
2423
is a QDomCharacterData; you can get the QDomCharacterData with
2426
\sa toCharacterData()
2428
bool QDomNode::isCharacterData() const
2431
return impl->isCharacterData();
2436
Returns true if the node is a comment; otherwise returns false.
2438
If this function returns true, it does not imply that this object
2439
is a QDomComment; you can get the QDomComment with toComment().
2443
bool QDomNode::isComment() const
2446
return impl->isComment();
2453
Returns the first child element with tag name \a tagName if tagName is non-empty;
2454
otherwise returns the last child element. Returns a null element if no
2457
\sa lastChildElement() previousSiblingElement() nextSiblingElement()
2460
QDomElement QDomNode::firstChildElement(const QString &tagName) const
2462
for (QDomNode child = firstChild(); !child.isNull(); child = child.nextSibling()) {
2463
if (child.isElement()) {
2464
QDomElement elt = child.toElement();
2465
if (tagName.isEmpty() || elt.tagName() == tagName)
2469
return QDomElement();
2473
Returns the last child element with tag name \a tagName if tagName is non-empty;
2474
otherwise returns the first child element. Returns a null element if no
2477
\sa firstChildElement() previousSiblingElement() nextSiblingElement()
2480
QDomElement QDomNode::lastChildElement(const QString &tagName) const
2482
for (QDomNode child = lastChild(); !child.isNull(); child = child.previousSibling()) {
2483
if (child.isElement()) {
2484
QDomElement elt = child.toElement();
2485
if (tagName.isEmpty() || elt.tagName() == tagName)
2489
return QDomElement();
2493
Returns the next sibilng element with tag name \a tagName if \a tagName
2494
is non-empty; otherwise returns any next sibling element.
2495
Returns a null element if no such sibling exists.
2497
\sa firstChildElement() previousSiblingElement() lastChildElement()
2500
QDomElement QDomNode::nextSiblingElement(const QString &tagName) const
2502
for (QDomNode sib = nextSibling(); !sib.isNull(); sib = sib.nextSibling()) {
2503
if (sib.isElement()) {
2504
QDomElement elt = sib.toElement();
2505
if (tagName.isEmpty() || elt.tagName() == tagName)
2509
return QDomElement();
2513
Returns the previous sibilng element with tag name \a tagName if \a tagName
2514
is non-empty; otherwise returns any previous sibling element.
2515
Returns a null element if no such sibling exists.
2517
\sa firstChildElement(), nextSiblingElement(), lastChildElement()
2520
QDomElement QDomNode::previousSiblingElement(const QString &tagName) const
2522
for (QDomNode sib = previousSibling(); !sib.isNull(); sib = sib.previousSibling()) {
2523
if (sib.isElement()) {
2524
QDomElement elt = sib.toElement();
2525
if (tagName.isEmpty() || elt.tagName() == tagName)
2529
return QDomElement();
2533
/**************************************************************
2535
* QDomNamedNodeMapPrivate
2537
**************************************************************/
2539
QDomNamedNodeMapPrivate::QDomNamedNodeMapPrivate(QDomNodePrivate* n)
2544
appendToParent = false;
2547
QDomNamedNodeMapPrivate::~QDomNamedNodeMapPrivate()
2552
QDomNamedNodeMapPrivate* QDomNamedNodeMapPrivate::clone(QDomNodePrivate* p)
2554
QDomNamedNodeMapPrivate* m = new QDomNamedNodeMapPrivate(p);
2555
m->readonly = readonly;
2556
m->appendToParent = appendToParent;
2558
QHash<QString, QDomNodePrivate*>::const_iterator it = map.constBegin();
2559
for (; it != map.constEnd(); ++it) {
2560
QDomNodePrivate *new_node = (*it)->cloneNode();
2561
new_node->setParent(p);
2562
m->setNamedItem(new_node);
2565
// we are no longer interested in ownership
2570
void QDomNamedNodeMapPrivate::clearMap()
2572
// Dereference all of our children if we took references
2573
if (!appendToParent) {
2574
QHash<QString, QDomNodePrivate *>::const_iterator it = map.constBegin();
2575
for (; it != map.constEnd(); ++it)
2576
if (!(*it)->ref.deref())
2582
QDomNodePrivate* QDomNamedNodeMapPrivate::namedItem(const QString& name) const
2584
QDomNodePrivate* p = map[name];
2588
QDomNodePrivate* QDomNamedNodeMapPrivate::namedItemNS(const QString& nsURI, const QString& localName) const
2590
QHash<QString, QDomNodePrivate *>::const_iterator it = map.constBegin();
2592
for (; it != map.constEnd(); ++it) {
2594
if (!n->prefix.isNull()) {
2595
// node has a namespace
2596
if (n->namespaceURI == nsURI && n->name == localName)
2603
QDomNodePrivate* QDomNamedNodeMapPrivate::setNamedItem(QDomNodePrivate* arg)
2605
if (readonly || !arg)
2609
return parent->appendChild(arg);
2611
QDomNodePrivate *n = map.value(arg->nodeName());
2612
// We take a reference
2614
map.insertMulti(arg->nodeName(), arg);
2618
QDomNodePrivate* QDomNamedNodeMapPrivate::setNamedItemNS(QDomNodePrivate* arg)
2620
if (readonly || !arg)
2624
return parent->appendChild(arg);
2626
if (!arg->prefix.isNull()) {
2627
// node has a namespace
2628
QDomNodePrivate *n = namedItemNS(arg->namespaceURI, arg->name);
2629
// We take a reference
2631
map.insertMulti(arg->nodeName(), arg);
2634
// ### check the following code if it is ok
2635
return setNamedItem(arg);
2639
QDomNodePrivate* QDomNamedNodeMapPrivate::removeNamedItem(const QString& name)
2644
QDomNodePrivate* p = namedItem(name);
2648
return parent->removeChild(p);
2650
map.remove(p->nodeName());
2651
// We took a reference, so we have to free one here
2656
QDomNodePrivate* QDomNamedNodeMapPrivate::item(int index) const
2658
if ((uint)index >= length())
2660
return *(map.constBegin() + index);
2663
uint QDomNamedNodeMapPrivate::length() const
2668
bool QDomNamedNodeMapPrivate::contains(const QString& name) const
2670
return map.value(name) != 0;
2673
bool QDomNamedNodeMapPrivate::containsNS(const QString& nsURI, const QString & localName) const
2675
return namedItemNS(nsURI, localName) != 0;
2678
/**************************************************************
2682
**************************************************************/
2684
#define IMPL ((QDomNamedNodeMapPrivate*)impl)
2687
\class QDomNamedNodeMap
2689
\brief The QDomNamedNodeMap class contains a collection of nodes
2690
that can be accessed by name.
2695
Note that QDomNamedNodeMap does not inherit from QDomNodeList.
2696
QDomNamedNodeMaps do not provide any specific node ordering.
2697
Although nodes in a QDomNamedNodeMap may be accessed by an ordinal
2698
index, this is simply to allow a convenient enumeration of the
2699
contents of a QDomNamedNodeMap, and does not imply that the DOM
2700
specifies an ordering of the nodes.
2702
The QDomNamedNodeMap is used in three places:
2704
\i QDomDocumentType::entities() returns a map of all entities
2705
described in the DTD.
2706
\i QDomDocumentType::notations() returns a map of all notations
2707
described in the DTD.
2708
\i QDomNode::attributes() returns a map of all attributes of an
2712
Items in the map are identified by the name which QDomNode::name()
2713
returns. Nodes are retrieved using namedItem(), namedItemNS() or
2714
item(). New nodes are inserted with setNamedItem() or
2715
setNamedItemNS() and removed with removeNamedItem() or
2716
removeNamedItemNS(). Use contains() to see if an item with the
2717
given name is in the named node map. The number of items is
2718
returned by length().
2720
Terminology: in this class we use "item" and "node"
2725
Constructs an empty named node map.
2727
QDomNamedNodeMap::QDomNamedNodeMap()
2733
Constructs a copy of \a n.
2735
QDomNamedNodeMap::QDomNamedNodeMap(const QDomNamedNodeMap &n)
2742
QDomNamedNodeMap::QDomNamedNodeMap(QDomNamedNodeMapPrivate *n)
2750
Assigns \a n to this named node map.
2752
QDomNamedNodeMap& QDomNamedNodeMap::operator=(const QDomNamedNodeMap &n)
2754
QDomNamedNodeMapPrivate *x = n.impl;
2757
x = qAtomicSetPtr(&impl, x);
2758
if (x && !x->ref.deref())
2764
Returns true if \a n and this named node map are equal; otherwise
2767
bool QDomNamedNodeMap::operator== (const QDomNamedNodeMap& n) const
2769
return (impl == n.impl);
2773
Returns true if \a n and this named node map are not equal;
2774
otherwise returns false.
2776
bool QDomNamedNodeMap::operator!= (const QDomNamedNodeMap& n) const
2778
return (impl != n.impl);
2782
Destroys the object and frees its resources.
2784
QDomNamedNodeMap::~QDomNamedNodeMap()
2786
if (impl && !impl->ref.deref())
2791
Returns the node called \a name.
2793
If the named node map does not contain such a node, a \link
2794
QDomNode::isNull() null node\endlink is returned. A node's name is
2795
the name returned by QDomNode::nodeName().
2797
\sa setNamedItem() namedItemNS()
2799
QDomNode QDomNamedNodeMap::namedItem(const QString& name) const
2803
return QDomNode(IMPL->namedItem(name));
2807
Inserts the node \a newNode into the named node map. The name used
2808
by the map is the node name of \a newNode as returned by
2809
QDomNode::nodeName().
2811
If the new node replaces an existing node, i.e. the map contains a
2812
node with the same name, the replaced node is returned.
2814
\sa namedItem() removeNamedItem() setNamedItemNS()
2816
QDomNode QDomNamedNodeMap::setNamedItem(const QDomNode& newNode)
2820
return QDomNode(IMPL->setNamedItem((QDomNodePrivate*)newNode.impl));
2824
Removes the node called \a name from the map.
2826
The function returns the removed node or a \link
2827
QDomNode::isNull() null node\endlink if the map did not contain a
2828
node called \a name.
2830
\sa setNamedItem() namedItem() removeNamedItemNS()
2832
QDomNode QDomNamedNodeMap::removeNamedItem(const QString& name)
2836
return QDomNode(IMPL->removeNamedItem(name));
2840
Retrieves the node at position \a index.
2842
This can be used to iterate over the map. Note that the nodes in
2843
the map are ordered arbitrarily.
2847
QDomNode QDomNamedNodeMap::item(int index) const
2851
return QDomNode(IMPL->item(index));
2855
Returns the node associated with the local name \a localName and
2856
the namespace URI \a nsURI.
2858
If the map does not contain such a node, a \link
2859
QDomNode::isNull() null node\endlink is returned.
2861
\sa setNamedItemNS() namedItem()
2863
QDomNode QDomNamedNodeMap::namedItemNS(const QString& nsURI, const QString& localName) const
2867
return QDomNode(IMPL->namedItemNS(nsURI, localName));
2871
Inserts the node \a newNode in the map. If a node with the same
2872
namespace URI and the same local name already exists in the map,
2873
it is replaced by \a newNode. If the new node replaces an existing
2874
node, the replaced node is returned.
2876
\sa namedItemNS() removeNamedItemNS() setNamedItem()
2878
QDomNode QDomNamedNodeMap::setNamedItemNS(const QDomNode& newNode)
2882
return QDomNode(IMPL->setNamedItemNS((QDomNodePrivate*)newNode.impl));
2886
Removes the node with the local name \a localName and the
2887
namespace URI \a nsURI from the map.
2889
The function returns the removed node or a \link
2890
QDomNode::isNull() null node\endlink if the map did not contain a
2891
node with the local name \a localName and the namespace URI \a
2894
\sa setNamedItemNS() namedItemNS() removeNamedItem()
2896
QDomNode QDomNamedNodeMap::removeNamedItemNS(const QString& nsURI, const QString& localName)
2900
QDomNodePrivate *n = IMPL->namedItemNS(nsURI, localName);
2903
return QDomNode(IMPL->removeNamedItem(n->name));
2907
Returns the number of nodes in the map.
2911
uint QDomNamedNodeMap::length() const
2915
return IMPL->length();
2919
\fn uint QDomNamedNodeMap::count() const
2921
Returns the number of nodes in the map.
2923
This function is the same as length().
2927
Returns true if the map contains a node called \a name; otherwise
2930
bool QDomNamedNodeMap::contains(const QString& name) const
2934
return IMPL->contains(name);
2939
/**************************************************************
2941
* QDomDocumentTypePrivate
2943
**************************************************************/
2945
QDomDocumentTypePrivate::QDomDocumentTypePrivate(QDomDocumentPrivate* doc, QDomNodePrivate* parent)
2946
: QDomNodePrivate(doc, parent)
2951
QDomDocumentTypePrivate::QDomDocumentTypePrivate(QDomDocumentTypePrivate* n, bool deep)
2952
: QDomNodePrivate(n, deep)
2955
// Refill the maps with our new children
2956
QDomNodePrivate* p = first;
2959
// Dont use normal insert function since we would create infinite recursion
2960
entities->map.insertMulti(p->nodeName(), p);
2961
if (p->isNotation())
2962
// Dont use normal insert function since we would create infinite recursion
2963
notations->map.insertMulti(p->nodeName(), p);
2967
QDomDocumentTypePrivate::~QDomDocumentTypePrivate()
2969
if (!entities->ref.deref())
2971
if (!notations->ref.deref())
2975
void QDomDocumentTypePrivate::init()
2977
entities = new QDomNamedNodeMapPrivate(this);
2978
notations = new QDomNamedNodeMapPrivate(this);
2981
internalSubset.clear();
2983
entities->setAppendToParent(true);
2984
notations->setAppendToParent(true);
2987
QDomNodePrivate* QDomDocumentTypePrivate::cloneNode(bool deep)
2989
QDomNodePrivate* p = new QDomDocumentTypePrivate(this, deep);
2990
// We are not interested in this node
2995
QDomNodePrivate* QDomDocumentTypePrivate::insertBefore(QDomNodePrivate* newChild, QDomNodePrivate* refChild)
2997
// Call the origianl implementation
2998
QDomNodePrivate* p = QDomNodePrivate::insertBefore(newChild, refChild);
3000
if (p && p->isEntity())
3001
entities->map.insertMulti(p->nodeName(), p);
3002
else if (p && p->isNotation())
3003
notations->map.insertMulti(p->nodeName(), p);
3008
QDomNodePrivate* QDomDocumentTypePrivate::insertAfter(QDomNodePrivate* newChild, QDomNodePrivate* refChild)
3010
// Call the origianl implementation
3011
QDomNodePrivate* p = QDomNodePrivate::insertAfter(newChild, refChild);
3013
if (p && p->isEntity())
3014
entities->map.insertMulti(p->nodeName(), p);
3015
else if (p && p->isNotation())
3016
notations->map.insertMulti(p->nodeName(), p);
3021
QDomNodePrivate* QDomDocumentTypePrivate::replaceChild(QDomNodePrivate* newChild, QDomNodePrivate* oldChild)
3023
// Call the origianl implementation
3024
QDomNodePrivate* p = QDomNodePrivate::replaceChild(newChild, oldChild);
3027
if (oldChild && oldChild->isEntity())
3028
entities->map.remove(oldChild->nodeName());
3029
else if (oldChild && oldChild->isNotation())
3030
notations->map.remove(oldChild->nodeName());
3033
entities->map.insertMulti(p->nodeName(), p);
3034
else if (p->isNotation())
3035
notations->map.insertMulti(p->nodeName(), p);
3041
QDomNodePrivate* QDomDocumentTypePrivate::removeChild(QDomNodePrivate* oldChild)
3043
// Call the origianl implementation
3044
QDomNodePrivate* p = QDomNodePrivate::removeChild( oldChild);
3046
if (p && p->isEntity())
3047
entities->map.remove(p->nodeName());
3048
else if (p && p->isNotation())
3049
notations->map.remove(p ->nodeName());
3054
QDomNodePrivate* QDomDocumentTypePrivate::appendChild(QDomNodePrivate* newChild)
3056
return insertAfter(newChild, 0);
3059
void QDomDocumentTypePrivate::save(QTextStream& s, int, int indent) const
3064
s << "<!DOCTYPE " << name;
3066
if (!publicId.isNull()) {
3067
s << " PUBLIC \"" << publicId << "\"";
3068
if (!systemId.isNull())
3069
s << " \"" << systemId << "\"";
3070
} else if (!systemId.isNull()) {
3071
s << " SYSTEM \"" << systemId << "\"";
3074
if (entities->length()>0 || notations->length()>0) {
3077
QHash<QString, QDomNodePrivate *>::const_iterator it2 = notations->map.constBegin();
3078
for (; it2 != notations->map.constEnd(); ++it2)
3079
(*it2)->save(s, 0, indent);
3081
QHash<QString, QDomNodePrivate *>::const_iterator it = entities->map.constBegin();
3082
for (; it != entities->map.constEnd(); ++it)
3083
(*it)->save(s, 0, indent);
3091
/**************************************************************
3095
**************************************************************/
3097
#define IMPL ((QDomDocumentTypePrivate*)impl)
3100
\class QDomDocumentType
3102
\brief The QDomDocumentType class is the representation of the DTD
3103
in the document tree.
3108
The QDomDocumentType class allows read-only access to some of the
3109
data structures in the DTD: it can return a map of all entities()
3110
and notations(). In addition the function name() returns the name
3111
of the document type as specified in the <!DOCTYPE name>
3112
tag. This class also provides the publicId(), systemId() and
3113
internalSubset() functions.
3119
Creates an empty QDomDocumentType object.
3121
QDomDocumentType::QDomDocumentType() : QDomNode()
3126
Constructs a copy of \a n.
3128
The data of the copy is shared (shallow copy): modifying one node
3129
will also change the other. If you want to make a deep copy, use
3132
QDomDocumentType::QDomDocumentType(const QDomDocumentType& n)
3137
QDomDocumentType::QDomDocumentType(QDomDocumentTypePrivate* n)
3143
Assigns \a n to this document type.
3145
The data of the copy is shared (shallow copy): modifying one node
3146
will also change the other. If you want to make a deep copy, use
3149
QDomDocumentType& QDomDocumentType::operator= (const QDomDocumentType& n)
3151
return (QDomDocumentType&) QDomNode::operator=(n);
3155
Returns the name of the document type as specified in the
3156
<!DOCTYPE name> tag.
3160
QString QDomDocumentType::name() const
3164
return IMPL->nodeName();
3168
Returns a map of all entities described in the DTD.
3170
QDomNamedNodeMap QDomDocumentType::entities() const
3173
return QDomNamedNodeMap();
3174
return QDomNamedNodeMap(IMPL->entities);
3178
Returns a map of all notations described in the DTD.
3180
QDomNamedNodeMap QDomDocumentType::notations() const
3183
return QDomNamedNodeMap();
3184
return QDomNamedNodeMap(IMPL->notations);
3188
Returns the public identifier of the external DTD subset or
3189
an empty string if there is no public identifier.
3191
\sa systemId() internalSubset() QDomImplementation::createDocumentType()
3193
QString QDomDocumentType::publicId() const
3197
return IMPL->publicId;
3201
Returns the system identifier of the external DTD subset or
3202
an empty string if there is no system identifier.
3204
\sa publicId() internalSubset() QDomImplementation::createDocumentType()
3206
QString QDomDocumentType::systemId() const
3210
return IMPL->systemId;
3214
Returns the internal subset of the document type or an empty
3215
string if there is no internal subset.
3217
\sa publicId() systemId()
3219
QString QDomDocumentType::internalSubset() const
3223
return IMPL->internalSubset;
3227
Are these needed at all? The only difference when removing these
3228
two methods in all subclasses is that we'd get a different type
3233
\fn QDomNode::NodeType QDomDocumentType::nodeType() const
3235
Returns \c DocumentTypeNode.
3237
\sa isDocumentType() QDomNode::toDocumentType()
3242
/**************************************************************
3244
* QDomDocumentFragmentPrivate
3246
**************************************************************/
3248
QDomDocumentFragmentPrivate::QDomDocumentFragmentPrivate(QDomDocumentPrivate* doc, QDomNodePrivate* parent)
3249
: QDomNodePrivate(doc, parent)
3251
name = "#document-fragment";
3254
QDomDocumentFragmentPrivate::QDomDocumentFragmentPrivate(QDomNodePrivate* n, bool deep)
3255
: QDomNodePrivate(n, deep)
3259
QDomNodePrivate* QDomDocumentFragmentPrivate::cloneNode(bool deep)
3261
QDomNodePrivate* p = new QDomDocumentFragmentPrivate(this, deep);
3262
// We are not interested in this node
3267
/**************************************************************
3269
* QDomDocumentFragment
3271
**************************************************************/
3273
#define IMPL ((QDomDocumentFragmentPrivate*)impl)
3276
\class QDomDocumentFragment
3278
\brief The QDomDocumentFragment class is a tree of QDomNodes which is not usually a complete QDomDocument.
3283
If you want to do complex tree operations it is useful to have a
3284
lightweight class to store nodes and their relations.
3285
QDomDocumentFragment stores a subtree of a document which does not
3286
necessarily represent a well-formed XML document.
3288
QDomDocumentFragment is also useful if you want to group several
3289
nodes in a list and insert them all together as children of some
3290
node. In these cases QDomDocumentFragment can be used as a
3291
temporary container for this list of children.
3293
The most important feature of QDomDocumentFragment is that it is
3294
treated in a special way by QDomNode::insertAfter(),
3295
QDomNode::insertBefore(), QDomNode::replaceChild() and
3296
QDomNode::appendChild(): instead of inserting the fragment itself, all
3297
the fragment's children are inserted.
3301
Constructs an empty document fragment.
3303
QDomDocumentFragment::QDomDocumentFragment()
3307
QDomDocumentFragment::QDomDocumentFragment(QDomDocumentFragmentPrivate* n)
3313
Constructs a copy of \a x.
3315
The data of the copy is shared (shallow copy): modifying one node
3316
will also change the other. If you want to make a deep copy, use
3319
QDomDocumentFragment::QDomDocumentFragment(const QDomDocumentFragment& x)
3325
Assigns \a x to this DOM document fragment.
3327
The data of the copy is shared (shallow copy): modifying one node
3328
will also change the other. If you want to make a deep copy, use
3331
QDomDocumentFragment& QDomDocumentFragment::operator= (const QDomDocumentFragment& x)
3333
return (QDomDocumentFragment&) QDomNode::operator=(x);
3337
\fn QDomNode::NodeType QDomDocumentFragment::nodeType() const
3339
Returns \c DocumentFragment.
3341
\sa isDocumentFragment() QDomNode::toDocumentFragment()
3346
/**************************************************************
3348
* QDomCharacterDataPrivate
3350
**************************************************************/
3352
QDomCharacterDataPrivate::QDomCharacterDataPrivate(QDomDocumentPrivate* d, QDomNodePrivate* p,
3353
const QString& data)
3354
: QDomNodePrivate(d, p)
3357
name = "#character-data";
3360
QDomCharacterDataPrivate::QDomCharacterDataPrivate(QDomCharacterDataPrivate* n, bool deep)
3361
: QDomNodePrivate(n, deep)
3365
QDomNodePrivate* QDomCharacterDataPrivate::cloneNode(bool deep)
3367
QDomNodePrivate* p = new QDomCharacterDataPrivate(this, deep);
3368
// We are not interested in this node
3373
uint QDomCharacterDataPrivate::dataLength() const
3375
return value.length();
3378
QString QDomCharacterDataPrivate::substringData(unsigned long offset, unsigned long n) const
3380
return value.mid(offset, n);
3383
void QDomCharacterDataPrivate::insertData(unsigned long offset, const QString& arg)
3385
value.insert(offset, arg);
3388
void QDomCharacterDataPrivate::deleteData(unsigned long offset, unsigned long n)
3390
value.remove(offset, n);
3393
void QDomCharacterDataPrivate::replaceData(unsigned long offset, unsigned long n, const QString& arg)
3395
value.replace(offset, n, arg);
3398
void QDomCharacterDataPrivate::appendData(const QString& arg)
3403
/**************************************************************
3407
**************************************************************/
3409
#define IMPL ((QDomCharacterDataPrivate*)impl)
3412
\class QDomCharacterData
3414
\brief The QDomCharacterData class represents a generic string in the DOM.
3419
Character data as used in XML specifies a generic data string.
3420
More specialized versions of this class are QDomText, QDomComment
3421
and QDomCDATASection.
3423
The data string is set with setData() and retrieved with data().
3424
You can retrieve a portion of the data string using
3425
substringData(). Extra data can be appended with appendData(), or
3426
inserted with insertData(). Portions of the data string can be
3427
deleted with deleteData() or replaced with replaceData(). The
3428
length of the data string is returned by length().
3430
The node type of the node containing this character data is
3431
returned by nodeType().
3433
\sa QDomText QDomComment QDomCDATASection
3437
Constructs an empty character data object.
3439
QDomCharacterData::QDomCharacterData()
3444
Constructs a copy of \a x.
3446
The data of the copy is shared (shallow copy): modifying one node
3447
will also change the other. If you want to make a deep copy, use
3450
QDomCharacterData::QDomCharacterData(const QDomCharacterData& x)
3455
QDomCharacterData::QDomCharacterData(QDomCharacterDataPrivate* n)
3461
Assigns \a x to this character data.
3463
The data of the copy is shared (shallow copy): modifying one node
3464
will also change the other. If you want to make a deep copy, use
3467
QDomCharacterData& QDomCharacterData::operator= (const QDomCharacterData& x)
3469
return (QDomCharacterData&) QDomNode::operator=(x);
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
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)
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, returns \c CharacterDataNode.
3556
QDomNode::NodeType QDomCharacterData::nodeType() const
3559
return CharacterDataNode;
3560
return QDomNode::nodeType();
3565
/**************************************************************
3569
**************************************************************/
3571
QDomAttrPrivate::QDomAttrPrivate(QDomDocumentPrivate* d, QDomNodePrivate* parent, const QString& name_)
3572
: QDomNodePrivate(d, parent)
3575
m_specified = false;
3578
QDomAttrPrivate::QDomAttrPrivate(QDomDocumentPrivate* d, QDomNodePrivate* p, const QString& nsURI, const QString& qName)
3579
: QDomNodePrivate(d, p)
3581
qt_split_namespace(prefix, name, qName, !nsURI.isNull());
3582
namespaceURI = nsURI;
3583
createdWithDom1Interface = false;
3584
m_specified = false;
3587
QDomAttrPrivate::QDomAttrPrivate(QDomAttrPrivate* n, bool deep)
3588
: QDomNodePrivate(n, deep)
3590
m_specified = n->specified();
3593
void QDomAttrPrivate::setNodeValue(const QString& v)
3596
QDomTextPrivate *t = new QDomTextPrivate(0, this, v);
3597
// keep the refcount balanced: appendChild() does a ref anyway.
3600
delete removeChild(first);
3605
QDomNodePrivate* QDomAttrPrivate::cloneNode(bool deep)
3607
QDomNodePrivate* p = new QDomAttrPrivate(this, deep);
3608
// We are not interested in this node
3613
bool QDomAttrPrivate::specified() const
3619
Encode an attribute value upon saving.
3621
static QString encodeAttr(const QString& str)
3624
uint len = tmp.length();
3627
if (tmp[(int)i] == '<') {
3628
tmp.replace(i, 1, "<");
3631
} else if (tmp[(int)i] == '"') {
3632
tmp.replace(i, 1, """);
3635
} else if (tmp[(int)i] == '&') {
3636
tmp.replace(i, 1, "&");
3639
} else if (tmp[(int)i] == '>' && i>=2 && tmp[(int)i-1]==']' && tmp[(int)i-2]==']') {
3640
tmp.replace(i, 1, ">");
3651
void QDomAttrPrivate::save(QTextStream& s, int, int) const
3653
if (namespaceURI.isNull()) {
3654
s << name << "=\"" << encodeAttr(value) << "\"";
3656
// ### optimize this (see comment of QDomElementPrivate::save()
3657
s << prefix << ":" << name << "=\"" << encodeAttr(value) << "\""
3658
<< " xmlns:" << prefix << "=\"" << encodeAttr(namespaceURI) << "\"";
3662
/**************************************************************
3666
**************************************************************/
3668
#define IMPL ((QDomAttrPrivate*)impl)
3673
\brief The QDomAttr class represents one attribute of a QDomElement.
3678
For example, the following piece of XML produces an element with
3679
no children, but two attributes:
3682
<link href="http://www.trolltech.com" color="red" />
3685
You can access the attributes of an element with code like this:
3688
QDomElement e = //...
3690
QDomAttr a = e.attributeNode("href");
3691
cout << a.value() << endl; // prints "http://www.trolltech.com"
3692
a.setValue("http://doc.trolltech.com"); // change the node's attribute
3693
QDomAttr a2 = e.attributeNode("href");
3694
cout << a2.value() << endl; // prints "http://doc.trolltech.com"
3697
This example also shows that changing an attribute received from
3698
an element changes the attribute of the element. If you do not
3699
want to change the value of the element's attribute you must
3700
use cloneNode() to get an independent copy of the attribute.
3702
QDomAttr can return the name() and value() of an attribute. An
3703
attribute's value is set with setValue(). If specified() returns
3704
true the value was either set in the document or set with
3705
setValue(); otherwise the value hasn't been set. The node this
3706
attribute is attached to (if any) is returned by ownerElement().
3708
For further information about the Document Object Model see
3709
\l{http://www.w3.org/TR/REC-DOM-Level-1/} and
3710
\l{http://www.w3.org/TR/DOM-Level-2-Core/}.
3711
For a more general introduction of the DOM implementation see the
3712
QDomDocument documentation.
3717
Constructs an empty attribute.
3719
QDomAttr::QDomAttr()
3724
Constructs a copy of \a x.
3726
The data of the copy is shared (shallow copy): modifying one node
3727
will also change the other. If you want to make a deep copy, use
3730
QDomAttr::QDomAttr(const QDomAttr& x)
3735
QDomAttr::QDomAttr(QDomAttrPrivate* n)
3741
Assigns \a x to this DOM attribute.
3743
The data of the copy is shared (shallow copy): modifying one node
3744
will also change the other. If you want to make a deep copy, use
3747
QDomAttr& QDomAttr::operator= (const QDomAttr& x)
3749
return (QDomAttr&) QDomNode::operator=(x);
3753
Returns the attribute's name.
3755
QString QDomAttr::name() const
3759
return impl->nodeName();
3763
Returns true if the attribute has either been expicitly specified
3764
in the XML document or was set by the user with setValue().
3765
Returns false if the value hasn't been specified or set.
3769
bool QDomAttr::specified() const
3773
return IMPL->specified();
3777
Returns the element node this attribute is attached to or a \link
3778
QDomNode::isNull() null node\endlink if this attribute is not
3779
attached to any element.
3781
QDomElement QDomAttr::ownerElement() const
3783
if (!impl && !impl->parent()->isElement())
3784
return QDomElement();
3785
return QDomElement((QDomElementPrivate*)(impl->parent()));
3789
Returns the value of the attribute or an empty string if the
3790
attribute has not been specified.
3792
\sa specified() setValue()
3794
QString QDomAttr::value() const
3798
return impl->nodeValue();
3802
Sets the attribute's value to \a v.
3806
void QDomAttr::setValue(const QString& v)
3810
impl->setNodeValue(v);
3811
IMPL->m_specified = true;
3815
\fn QDomNode::NodeType QDomAttr::nodeType() const
3817
Returns \link QDomNode::NodeType AttributeNode\endlink.
3822
/**************************************************************
3824
* QDomElementPrivate
3826
**************************************************************/
3828
QDomElementPrivate::QDomElementPrivate(QDomDocumentPrivate* d, QDomNodePrivate* p,
3829
const QString& tagname)
3830
: QDomNodePrivate(d, p)
3833
m_attr = new QDomNamedNodeMapPrivate(this);
3836
QDomElementPrivate::QDomElementPrivate(QDomDocumentPrivate* d, QDomNodePrivate* p,
3837
const QString& nsURI, const QString& qName)
3838
: QDomNodePrivate(d, p)
3840
qt_split_namespace(prefix, name, qName, !nsURI.isNull());
3841
namespaceURI = nsURI;
3842
createdWithDom1Interface = false;
3843
m_attr = new QDomNamedNodeMapPrivate(this);
3846
QDomElementPrivate::QDomElementPrivate(QDomElementPrivate* n, bool deep) :
3847
QDomNodePrivate(n, deep)
3849
m_attr = n->m_attr->clone(this);
3850
// Reference is down to 0, so we set it to 1 here.
3854
QDomElementPrivate::~QDomElementPrivate()
3856
if (!m_attr->ref.deref())
3860
QDomNodePrivate* QDomElementPrivate::cloneNode(bool deep)
3862
QDomNodePrivate* p = new QDomElementPrivate(this, deep);
3863
// We are not interested in this node
3868
QString QDomElementPrivate::attribute(const QString& name_, const QString& defValue) const
3870
QDomNodePrivate* n = m_attr->namedItem(name_);
3874
return n->nodeValue();
3877
QString QDomElementPrivate::attributeNS(const QString& nsURI, const QString& localName, const QString& defValue) const
3879
QDomNodePrivate* n = m_attr->namedItemNS(nsURI, localName);
3883
return n->nodeValue();
3886
void QDomElementPrivate::setAttribute(const QString& aname, const QString& newValue)
3888
QDomNodePrivate* n = m_attr->namedItem(aname);
3890
n = new QDomAttrPrivate(ownerDocument(), this, aname);
3891
n->setNodeValue(newValue);
3893
// Referencing is done by the map, so we set the reference counter back
3894
// to 0 here. This is ok since we created the QDomAttrPrivate.
3896
m_attr->setNamedItem(n);
3898
n->setNodeValue(newValue);
3902
void QDomElementPrivate::setAttributeNS(const QString& nsURI, const QString& qName, const QString& newValue)
3904
QString prefix, localName;
3905
qt_split_namespace(prefix, localName, qName, true);
3906
QDomNodePrivate* n = m_attr->namedItemNS(nsURI, localName);
3908
n = new QDomAttrPrivate(ownerDocument(), this, nsURI, qName);
3909
n->setNodeValue(newValue);
3911
// Referencing is done by the map, so we set the reference counter back
3912
// to 0 here. This is ok since we created the QDomAttrPrivate.
3914
m_attr->setNamedItem(n);
3916
n->setNodeValue(newValue);
3921
void QDomElementPrivate::removeAttribute(const QString& aname)
3923
QDomNodePrivate* p = m_attr->removeNamedItem(aname);
3924
if (p && p->ref == 0)
3928
QDomAttrPrivate* QDomElementPrivate::attributeNode(const QString& aname)
3930
return (QDomAttrPrivate*)m_attr->namedItem(aname);
3933
QDomAttrPrivate* QDomElementPrivate::attributeNodeNS(const QString& nsURI, const QString& localName)
3935
return (QDomAttrPrivate*)m_attr->namedItemNS(nsURI, localName);
3938
QDomAttrPrivate* QDomElementPrivate::setAttributeNode(QDomAttrPrivate* newAttr)
3940
QDomNodePrivate* n = m_attr->namedItem(newAttr->nodeName());
3942
// Referencing is done by the maps
3943
m_attr->setNamedItem(newAttr);
3945
return (QDomAttrPrivate*)n;
3948
QDomAttrPrivate* QDomElementPrivate::setAttributeNodeNS(QDomAttrPrivate* newAttr)
3950
QDomNodePrivate* n = 0;
3951
if (!newAttr->prefix.isNull())
3952
n = m_attr->namedItemNS(newAttr->namespaceURI, newAttr->name);
3954
// Referencing is done by the maps
3955
m_attr->setNamedItem(newAttr);
3957
return (QDomAttrPrivate*)n;
3960
QDomAttrPrivate* QDomElementPrivate::removeAttributeNode(QDomAttrPrivate* oldAttr)
3962
return (QDomAttrPrivate*)m_attr->removeNamedItem(oldAttr->nodeName());
3965
bool QDomElementPrivate::hasAttribute(const QString& aname)
3967
return m_attr->contains(aname);
3970
bool QDomElementPrivate::hasAttributeNS(const QString& nsURI, const QString& localName)
3972
return m_attr->containsNS(nsURI, localName);
3975
QString QDomElementPrivate::text()
3979
QDomNodePrivate* p = first;
3981
if (p->isText() || p->isCDATASection())
3982
t += p->nodeValue();
3983
else if (p->isElement())
3984
t += ((QDomElementPrivate*)p)->text();
3991
void QDomElementPrivate::save(QTextStream& s, int depth, int indent) const
3993
if (!(prev && prev->isText()))
3994
for (int i = 0; i < depth*indent; ++i)
3997
QString qName(name);
3999
if (!namespaceURI.isNull()) {
4000
// ### optimize this, so that you only declare namespaces that are not
4001
// yet declared -- we loose default namespace mappings, so maybe we
4002
// should rather store the information that we get from
4003
// startPrefixMapping()/endPrefixMapping() and use them (you have to
4004
// take care if the DOM tree is modified, though)
4005
if (prefix.isEmpty()) {
4008
qName = prefix + ":" + name;
4009
nsDecl = " xmlns:" + prefix;
4011
nsDecl += "=\"" + encodeAttr(namespaceURI) + "\"";
4013
s << "<" << qName << nsDecl;
4015
if (!m_attr->map.isEmpty()) {
4017
QHash<QString, QDomNodePrivate *>::const_iterator it = m_attr->map.constBegin();
4018
for (; it != m_attr->map.constEnd(); ++it) {
4019
(*it)->save(s, 0, indent);
4026
if (first->isText())
4030
QDomNodePrivate::save(s, depth + 1, indent);
4031
if (!last->isText())
4032
for(int i = 0; i < depth*indent; ++i)
4035
s << "</" << qName << ">";
4039
if (!(next && next->isText()))
4043
/**************************************************************
4047
**************************************************************/
4049
#define IMPL ((QDomElementPrivate*)impl)
4054
\brief The QDomElement class represents one element in the DOM tree.
4059
Elements have a tagName() and zero or more attributes associated
4060
with them. The tag name can be changed with setTagName().
4062
Element attributes are represented by QDomAttr objects that can
4063
be queried using the attribute() and attributeNode() functions.
4064
You can set attributes with the setAttribute() and
4065
setAttributeNode() functions. Attributes can be removed with
4066
removeAttribute(). There are namespace-aware equivalents to these
4067
functions, i.e. setAttributeNS(), setAttributeNodeNS() and
4068
removeAttributeNS().
4070
If you want to access the text of a node use text(), e.g.
4072
QDomElement e = //...
4074
QString s = e.text()
4076
The text() function operates recursively to find the text (since
4077
not all elements contain text). If you want to find all the text
4078
in all of a node's children, iterate over the children looking for
4079
QDomText nodes, e.g.
4082
QDomElement element = doc.documentElement();
4083
for(QDomNode n = element.firstChild(); !n.isNull(); n = n.nextSibling())
4085
QDomText t = n.toText();
4090
Note that we attempt to convert each node to a text node and use
4091
text() rather than using firstChild().toText().data() or
4092
n.toText().data() directly on the node, because the node may not
4095
You can get a list of all the decendents of an element which have
4096
a specified tag name with elementsByTagName() or
4097
elementsByTagNameNS().
4099
To browse the elements of a dom document use firstChildElement(), lastChildElement(),
4100
nextSiblingElement() and previousSiblingElement(). For example, to iterate over all
4101
child elements called "entry" in a root element called "database", you can use:
4103
QDomDocument doc = // ...
4104
QDomElement root = doc.firstChildElement("database");
4105
QDomElement elt = root.firstChildElement("entry");
4106
for (; !elt.isNull(); elt = elt.nextSiblingElelement("entry")) {
4111
For further information about the Document Object Model see
4112
\l{http://www.w3.org/TR/REC-DOM-Level-1/}{Level 1} and
4113
\l{http://www.w3.org/TR/DOM-Level-2-Core/}{Level 2 Core}.
4114
For a more general introduction of the DOM implementation see the
4115
QDomDocument documentation.
4119
Constructs an empty element. Use the QDomDocument::createElement()
4120
function to construct elements with content.
4122
QDomElement::QDomElement()
4128
Constructs a copy of \a x.
4130
The data of the copy is shared (shallow copy): modifying one node
4131
will also change the other. If you want to make a deep copy, use
4134
QDomElement::QDomElement(const QDomElement& x)
4139
QDomElement::QDomElement(QDomElementPrivate* n)
4145
Assigns \a x to this DOM element.
4147
The data of the copy is shared (shallow copy): modifying one node
4148
will also change the other. If you want to make a deep copy, use
4151
QDomElement& QDomElement::operator= (const QDomElement& x)
4153
return (QDomElement&) QDomNode::operator=(x);
4157
\fn QDomNode::NodeType QDomElement::nodeType() const
4159
Returns \c ElementNode.
4163
Sets this element's tag name to \a name.
4167
void QDomElement::setTagName(const QString& name)
4174
Returns the tag name of this element. For an XML element like this:
4177
<img src="myimg.png">
4180
the tagname would return "img".
4184
QString QDomElement::tagName() const
4188
return impl->nodeName();
4193
Returns a QDomNamedNodeMap containing all this element's attributes.
4195
\sa attribute() setAttribute() attributeNode() setAttributeNode()
4197
QDomNamedNodeMap QDomElement::attributes() const
4200
return QDomNamedNodeMap();
4201
return QDomNamedNodeMap(IMPL->attributes());
4205
Returns the attribute called \a name. If the attribute does not
4206
exist \a defValue is returned.
4208
\sa setAttribute() attributeNode() setAttributeNode() attributeNS()
4210
QString QDomElement::attribute(const QString& name, const QString& defValue) const
4214
return IMPL->attribute(name, defValue);
4218
Adds an attribute called \a name with value \a value. If an
4219
attribute with the same name exists, its value is replaced by \a
4222
\sa attribute() setAttributeNode() setAttributeNS()
4224
void QDomElement::setAttribute(const QString& name, const QString& value)
4228
IMPL->setAttribute(name, value);
4232
\fn void QDomElement::setAttribute(const QString& name, int value)
4238
\fn void QDomElement::setAttribute(const QString& name, uint value)
4246
void QDomElement::setAttribute(const QString& name, qlonglong value)
4252
IMPL->setAttribute(name, x);
4258
void QDomElement::setAttribute(const QString& name, qulonglong value)
4264
IMPL->setAttribute(name, x);
4270
void QDomElement::setAttribute(const QString& name, double value)
4276
IMPL->setAttribute(name, x);
4280
Removes the attribute called name \a name from this element.
4282
\sa setAttribute() attribute() removeAttributeNS()
4284
void QDomElement::removeAttribute(const QString& name)
4288
IMPL->removeAttribute(name);
4292
Returns the QDomAttr object that corresponds to the attribute
4293
called \a name. If no such attribute exists a \link
4294
QDomNode::isNull() null attribute\endlink is returned.
4296
\sa setAttributeNode() attribute() setAttribute() attributeNodeNS()
4298
QDomAttr QDomElement::attributeNode(const QString& name)
4302
return QDomAttr(IMPL->attributeNode(name));
4306
Adds the attribute \a newAttr to this element.
4308
If the element has another attribute that has the same name as \a
4309
newAttr, this function replaces that attribute and returns it;
4310
otherwise the function returns a \link QDomNode::isNull() null
4313
\sa attributeNode() setAttribute() setAttributeNodeNS()
4315
QDomAttr QDomElement::setAttributeNode(const QDomAttr& newAttr)
4319
return QDomAttr(IMPL->setAttributeNode(((QDomAttrPrivate*)newAttr.impl)));
4323
Removes the attribute \a oldAttr from the element and returns it.
4325
\sa attributeNode() setAttributeNode()
4327
QDomAttr QDomElement::removeAttributeNode(const QDomAttr& oldAttr)
4330
return QDomAttr(); // ### should this return oldAttr?
4331
return QDomAttr(IMPL->removeAttributeNode(((QDomAttrPrivate*)oldAttr.impl)));
4335
Returns a QDomNodeList containing all descendent elements of this
4336
element that are called \a tagname. The order they are in the node
4337
list is the order they are encountered in a preorder traversal of
4340
\sa elementsByTagNameNS() QDomDocument::elementsByTagName()
4342
QDomNodeList QDomElement::elementsByTagName(const QString& tagname) const
4344
return QDomNodeList(new QDomNodeListPrivate(impl, tagname));
4348
Returns true if this element has an attribute called \a name;
4349
otherwise returns false.
4351
bool QDomElement::hasAttribute(const QString& name) const
4355
return IMPL->hasAttribute(name);
4359
Returns the attribute with the local name \a localName and the
4360
namespace URI \a nsURI. If the attribute does not exist \a
4361
defValue is returned.
4363
\sa setAttributeNS() attributeNodeNS() setAttributeNodeNS() attribute()
4365
QString QDomElement::attributeNS(const QString nsURI, const QString& localName, const QString& defValue) const
4369
return IMPL->attributeNS(nsURI, localName, defValue);
4373
Adds an attribute with the qualified name \a qName and the
4374
namespace URI \a nsURI with the value \a value. If an attribute
4375
with the same local name and namespace URI exists, its prefix is
4376
replaced by the prefix of \a qName and its value is repaced by \a
4379
Although \a qName is the qualified name, the local name is used to
4380
decide if an existing attribute's value should be replaced.
4382
\sa attributeNS() setAttributeNodeNS() setAttribute()
4384
void QDomElement::setAttributeNS(const QString nsURI, const QString& qName, const QString& value)
4388
IMPL->setAttributeNS(nsURI, qName, value);
4392
\fn void QDomElement::setAttributeNS(const QString nsURI, const QString& qName, int value)
4398
\fn void QDomElement::setAttributeNS(const QString nsURI, const QString& qName, uint value)
4406
void QDomElement::setAttributeNS(const QString nsURI, const QString& qName, qlonglong value)
4412
IMPL->setAttributeNS(nsURI, qName, x);
4418
void QDomElement::setAttributeNS(const QString nsURI, const QString& qName, qulonglong value)
4424
IMPL->setAttributeNS(nsURI, qName, x);
4430
void QDomElement::setAttributeNS(const QString nsURI, const QString& qName, double value)
4436
IMPL->setAttributeNS(nsURI, qName, x);
4440
Removes the attribute with the local name \a localName and the
4441
namespace URI \a nsURI from this element.
4443
\sa setAttributeNS() attributeNS() removeAttribute()
4445
void QDomElement::removeAttributeNS(const QString& nsURI, const QString& localName)
4449
QDomNodePrivate *n = IMPL->attributeNodeNS(nsURI, localName);
4452
IMPL->removeAttribute(n->nodeName());
4456
Returns the QDomAttr object that corresponds to the attribute
4457
with the local name \a localName and the namespace URI \a nsURI.
4458
If no such attribute exists a \l{QDomNode::isNull()}{null
4459
attribute} is returned.
4461
\sa setAttributeNode() attribute() setAttribute()
4463
QDomAttr QDomElement::attributeNodeNS(const QString& nsURI, const QString& localName)
4467
return QDomAttr(IMPL->attributeNodeNS(nsURI, localName));
4471
Adds the attribute \a newAttr to this element.
4473
If the element has another attribute that has the same local name
4474
and namespace URI as \a newAttr, this function replaces that
4475
attribute and returns it; otherwise the function returns a \link
4476
QDomNode::isNull() null attribute\endlink.
4478
\sa attributeNodeNS() setAttributeNS() setAttributeNode()
4480
QDomAttr QDomElement::setAttributeNodeNS(const QDomAttr& newAttr)
4484
return QDomAttr(IMPL->setAttributeNodeNS(((QDomAttrPrivate*)newAttr.impl)));
4488
Returns a QDomNodeList containing all the descendent elements of
4489
this element with the local name \a localName and the namespace
4490
URI \a nsURI. The order they are in the node list is the order
4491
they are encountered in a preorder traversal of the element tree.
4493
\sa elementsByTagName() QDomDocument::elementsByTagNameNS()
4495
QDomNodeList QDomElement::elementsByTagNameNS(const QString& nsURI, const QString& localName) const
4497
return QDomNodeList(new QDomNodeListPrivate(impl, nsURI, localName));
4501
Returns true if this element has an attribute with the local name
4502
\a localName and the namespace URI \a nsURI; otherwise returns
4505
bool QDomElement::hasAttributeNS(const QString& nsURI, const QString& localName) const
4509
return IMPL->hasAttributeNS(nsURI, localName);
4513
Returns the element's text or an empty string.
4517
<h1>Hello <b>Qt</b> <![CDATA[<xml is cool>]]></h1>
4520
The function text() of the QDomElement for the <h1> tag,
4521
will return "Hello Qt <xml is cool>".
4523
Comments are ignored by this function. It only evaluates QDomText
4524
and QDomCDATASection objects.
4526
QString QDomElement::text() const
4530
return IMPL->text();
4535
/**************************************************************
4539
**************************************************************/
4541
QDomTextPrivate::QDomTextPrivate(QDomDocumentPrivate* d, QDomNodePrivate* parent, const QString& val)
4542
: QDomCharacterDataPrivate(d, parent, val)
4547
QDomTextPrivate::QDomTextPrivate(QDomTextPrivate* n, bool deep)
4548
: QDomCharacterDataPrivate(n, deep)
4552
QDomNodePrivate* QDomTextPrivate::cloneNode(bool deep)
4554
QDomNodePrivate* p = new QDomTextPrivate(this, deep);
4555
// We are not interested in this node
4560
QDomTextPrivate* QDomTextPrivate::splitText(int offset)
4563
qWarning("QDomText::splitText The node has no parent. So I can not split");
4567
QDomTextPrivate* t = new QDomTextPrivate(ownerDocument(), 0, value.mid(offset));
4568
value.truncate(offset);
4570
parent()->insertAfter(t, this);
4575
void QDomTextPrivate::save(QTextStream& s, int, int) const
4577
s << encodeAttr(value);
4580
/**************************************************************
4584
**************************************************************/
4586
#define IMPL ((QDomTextPrivate*)impl)
4591
\brief The QDomText class represents text data in the parsed XML document.
4596
You can split the text in a QDomText object over two QDomText
4597
objecs with splitText().
4599
For further information about the Document Object Model see
4600
\l{http://www.w3.org/TR/REC-DOM-Level-1/}{Level 1} and
4601
\l{http://www.w3.org/TR/DOM-Level-2-Core/}{Level 2 Core}.
4602
For a more general introduction of the DOM implementation see the
4603
QDomDocument documentation.
4607
Constructs an empty QDomText object.
4609
To construct a QDomText with content, use QDomDocument::createTextNode().
4611
QDomText::QDomText()
4612
: QDomCharacterData()
4617
Constructs a copy of \a x.
4619
The data of the copy is shared (shallow copy): modifying one node
4620
will also change the other. If you want to make a deep copy, use
4623
QDomText::QDomText(const QDomText& x)
4624
: QDomCharacterData(x)
4628
QDomText::QDomText(QDomTextPrivate* n)
4629
: QDomCharacterData(n)
4634
Assigns \a x to this DOM text.
4636
The data of the copy is shared (shallow copy): modifying one node
4637
will also change the other. If you want to make a deep copy, use
4640
QDomText& QDomText::operator= (const QDomText& x)
4642
return (QDomText&) QDomNode::operator=(x);
4646
\fn QDomNode::NodeType QDomText::nodeType() const
4648
Returns \c TextNode.
4652
Splits this DOM text object into two QDomText objects. This object
4653
keeps its first \a offset characters and the second (newly
4654
created) object is inserted into the document tree after this
4655
object with the remaining characters.
4657
The function returns the newly created object.
4659
\sa QDomNode::normalize()
4661
QDomText QDomText::splitText(int offset)
4665
return QDomText(IMPL->splitText(offset));
4670
/**************************************************************
4672
* QDomCommentPrivate
4674
**************************************************************/
4676
QDomCommentPrivate::QDomCommentPrivate(QDomDocumentPrivate* d, QDomNodePrivate* parent, const QString& val)
4677
: QDomCharacterDataPrivate(d, parent, val)
4682
QDomCommentPrivate::QDomCommentPrivate(QDomCommentPrivate* n, bool deep)
4683
: QDomCharacterDataPrivate(n, deep)
4688
QDomNodePrivate* QDomCommentPrivate::cloneNode(bool deep)
4690
QDomNodePrivate* p = new QDomCommentPrivate(this, deep);
4691
// We are not interested in this node
4696
void QDomCommentPrivate::save(QTextStream& s, int, int) const
4698
s << "<!--" << value << "-->";
4701
/**************************************************************
4705
**************************************************************/
4707
#define IMPL ((QDomCommentPrivate*)impl)
4712
\brief The QDomComment class represents an XML comment.
4717
A comment in the parsed XML such as this:
4719
<!-- this is a comment -->
4721
is represented by QDomComment objects in the parsed Dom tree.
4723
For further information about the Document Object Model see
4724
\l{http://www.w3.org/TR/REC-DOM-Level-1/} and
4725
\l{http://www.w3.org/TR/DOM-Level-2-Core/}.
4726
For a more general introduction of the DOM implementation see the
4727
QDomDocument documentation.
4731
Constructs an empty comment. To construct a comment with content,
4732
use the QDomDocument::createComment() function.
4734
QDomComment::QDomComment()
4735
: QDomCharacterData()
4740
Constructs a copy of \a x.
4742
The data of the copy is shared (shallow copy): modifying one node
4743
will also change the other. If you want to make a deep copy, use
4746
QDomComment::QDomComment(const QDomComment& x)
4747
: QDomCharacterData(x)
4751
QDomComment::QDomComment(QDomCommentPrivate* n)
4752
: QDomCharacterData(n)
4757
Assigns \a x to this DOM comment.
4759
The data of the copy is shared (shallow copy): modifying one node
4760
will also change the other. If you want to make a deep copy, use
4763
QDomComment& QDomComment::operator= (const QDomComment& x)
4765
return (QDomComment&) QDomNode::operator=(x);
4769
\fn QDomNode::NodeType QDomComment::nodeType() const
4771
Returns \c CommentNode.
4776
/**************************************************************
4778
* QDomCDATASectionPrivate
4780
**************************************************************/
4782
QDomCDATASectionPrivate::QDomCDATASectionPrivate(QDomDocumentPrivate* d, QDomNodePrivate* parent,
4784
: QDomTextPrivate(d, parent, val)
4786
name = "#cdata-section";
4789
QDomCDATASectionPrivate::QDomCDATASectionPrivate(QDomCDATASectionPrivate* n, bool deep)
4790
: QDomTextPrivate(n, deep)
4794
QDomNodePrivate* QDomCDATASectionPrivate::cloneNode(bool deep)
4796
QDomNodePrivate* p = new QDomCDATASectionPrivate(this, deep);
4797
// We are not interested in this node
4802
void QDomCDATASectionPrivate::save(QTextStream& s, int, int) const
4804
// ### How do we escape "]]>" ?
4805
// "]]>" is not allowed; so there should be none in value anyway
4806
s << "<![CDATA[" << value << "]]>";
4809
/**************************************************************
4813
**************************************************************/
4815
#define IMPL ((QDomCDATASectionPrivate*)impl)
4818
\class QDomCDATASection
4820
\brief The QDomCDATASection class represents an XML CDATA section.
4825
CDATA sections are used to escape blocks of text containing
4826
characters that would otherwise be regarded as markup. The only
4827
delimiter that is recognized in a CDATA section is the "]]>"
4828
string that terminates the CDATA section. CDATA sections cannot be
4829
nested. Their primary purpose is for including material such as
4830
XML fragments, without needing to escape all the delimiters.
4832
Adjacent QDomCDATASection nodes are not merged by the
4833
QDomNode::normalize() function.
4835
For further information about the Document Object Model see
4836
\l{http://www.w3.org/TR/REC-DOM-Level-1/} and
4837
\l{http://www.w3.org/TR/DOM-Level-2-Core/}.
4838
For a more general introduction of the DOM implementation see the
4839
QDomDocument documentation.
4843
Constructs an empty CDATA section. To create a CDATA section with
4844
content, use the QDomDocument::createCDATASection() function.
4846
QDomCDATASection::QDomCDATASection()
4852
Constructs a copy of \a x.
4854
The data of the copy is shared (shallow copy): modifying one node
4855
will also change the other. If you want to make a deep copy, use
4858
QDomCDATASection::QDomCDATASection(const QDomCDATASection& x)
4863
QDomCDATASection::QDomCDATASection(QDomCDATASectionPrivate* n)
4869
Assigns \a x to this CDATA section.
4871
The data of the copy is shared (shallow copy): modifying one node
4872
will also change the other. If you want to make a deep copy, use
4875
QDomCDATASection& QDomCDATASection::operator= (const QDomCDATASection& x)
4877
return (QDomCDATASection&) QDomNode::operator=(x);
4881
\fn QDomNode::NodeType QDomCDATASection::nodeType() const
4883
Returns \c CDATASection.
4888
/**************************************************************
4890
* QDomNotationPrivate
4892
**************************************************************/
4894
QDomNotationPrivate::QDomNotationPrivate(QDomDocumentPrivate* d, QDomNodePrivate* parent,
4895
const QString& aname,
4896
const QString& pub, const QString& sys)
4897
: QDomNodePrivate(d, parent)
4904
QDomNotationPrivate::QDomNotationPrivate(QDomNotationPrivate* n, bool deep)
4905
: QDomNodePrivate(n, deep)
4911
QDomNodePrivate* QDomNotationPrivate::cloneNode(bool deep)
4913
QDomNodePrivate* p = new QDomNotationPrivate(this, deep);
4914
// We are not interested in this node
4919
void QDomNotationPrivate::save(QTextStream& s, int, int) const
4921
s << "<!NOTATION " << name << " ";
4922
if (!m_pub.isNull()) {
4923
s << "PUBLIC \"" << m_pub << "\"";
4924
if (!m_sys.isNull())
4925
s << " \"" << m_sys << "\"";
4927
s << "SYSTEM \"" << m_sys << "\"";
4932
/**************************************************************
4936
**************************************************************/
4938
#define IMPL ((QDomNotationPrivate*)impl)
4943
\brief The QDomNotation class represents an XML notation.
4948
A notation either declares, by name, the format of an unparsed
4949
entity (see section 4.7 of the XML 1.0 specification), or is used
4950
for formal declaration of processing instruction targets (see
4951
section 2.6 of the XML 1.0 specification).
4953
DOM does not support editing notation nodes; they are therefore
4956
A notation node does not have any parent.
4958
You can retrieve the publicId() and systemId() from a notation
4961
For further information about the Document Object Model see
4962
\l{http://www.w3.org/TR/REC-DOM-Level-1/}{Level 1} and
4963
\l{http://www.w3.org/TR/DOM-Level-2-Core/}{Level 2 Core}.
4964
For a more general introduction of the DOM implementation see the
4965
QDomDocument documentation.
4972
QDomNotation::QDomNotation()
4978
Constructs a copy of \a x.
4980
The data of the copy is shared (shallow copy): modifying one node
4981
will also change the other. If you want to make a deep copy, use
4984
QDomNotation::QDomNotation(const QDomNotation& x)
4989
QDomNotation::QDomNotation(QDomNotationPrivate* n)
4995
Assigns \a x to this DOM notation.
4997
The data of the copy is shared (shallow copy): modifying one node
4998
will also change the other. If you want to make a deep copy, use
5001
QDomNotation& QDomNotation::operator= (const QDomNotation& x)
5003
return (QDomNotation&) QDomNode::operator=(x);
5007
\fn QDomNode::NodeType QDomNotation::nodeType() const
5009
Returns \c NotationNode.
5013
Returns the public identifier of this notation.
5015
QString QDomNotation::publicId() const
5023
Returns the system identifier of this notation.
5025
QString QDomNotation::systemId() const
5034
/**************************************************************
5038
**************************************************************/
5040
QDomEntityPrivate::QDomEntityPrivate(QDomDocumentPrivate* d, QDomNodePrivate* parent,
5041
const QString& aname,
5042
const QString& pub, const QString& sys, const QString& notation)
5043
: QDomNodePrivate(d, parent)
5048
m_notationName = notation;
5051
QDomEntityPrivate::QDomEntityPrivate(QDomEntityPrivate* n, bool deep)
5052
: QDomNodePrivate(n, deep)
5056
m_notationName = n->m_notationName;
5059
QDomNodePrivate* QDomEntityPrivate::cloneNode(bool deep)
5061
QDomNodePrivate* p = new QDomEntityPrivate(this, deep);
5062
// We are not interested in this node
5068
Encode an entity value upon saving.
5070
static QByteArray encodeEntity(const QByteArray& str)
5072
QByteArray tmp(str);
5073
uint len = tmp.size();
5075
const char* d = tmp.data();
5078
tmp.replace(i, 1, "<");
5083
else if (d[i] == '"') {
5084
tmp.replace(i, 1, """);
5088
} else if (d[i] == '&' && i + 1 < len && d[i+1] == '#') {
5089
// Dont encode < or " or &custom;.
5090
// Only encode character references
5091
tmp.replace(i, 1, "&");
5103
void QDomEntityPrivate::save(QTextStream& s, int, int) const
5105
if (m_sys.isNull() && m_pub.isNull()) {
5106
s << "<!ENTITY " << name << " \"" << encodeEntity(value.toUtf8()) << "\">" << endl;
5108
s << "<!ENTITY " << name << " ";
5109
if (m_pub.isNull()) {
5110
s << "SYSTEM \"" << m_sys << "\"";
5112
s << "PUBLIC \"" << m_pub << "\" \"" << m_sys << "\"";
5114
if (! m_notationName.isNull()) {
5115
s << " NDATA " << m_notationName;
5121
/**************************************************************
5125
**************************************************************/
5127
#define IMPL ((QDomEntityPrivate*)impl)
5132
\brief The QDomEntity class represents an XML entity.
5137
This class represents an entity in an XML document, either parsed
5138
or unparsed. Note that this models the entity itself not the
5141
DOM does not support editing entity nodes; if a user wants to make
5142
changes to the contents of an entity, every related
5143
QDomEntityReference node must be replaced in the DOM tree by a
5144
clone of the entity's contents, and then the desired changes must
5145
be made to each of the clones instead. All the descendents of an
5146
entity node are read-only.
5148
An entity node does not have any parent.
5150
You can access the entity's publicId(), systemId() and
5151
notationName() when available.
5153
For further information about the Document Object Model see
5154
\l{http://www.w3.org/TR/REC-DOM-Level-1/}{Level 1} and
5155
\l{http://www.w3.org/TR/DOM-Level-2-Core/}{Level 2 Core}.
5156
For a more general introduction of the DOM implementation see the
5157
QDomDocument documentation.
5162
Constructs an empty entity.
5164
QDomEntity::QDomEntity()
5171
Constructs a copy of \a x.
5173
The data of the copy is shared (shallow copy): modifying one node
5174
will also change the other. If you want to make a deep copy, use
5177
QDomEntity::QDomEntity(const QDomEntity& x)
5182
QDomEntity::QDomEntity(QDomEntityPrivate* n)
5188
Assigns \a x to this DOM entity.
5190
The data of the copy is shared (shallow copy): modifying one node
5191
will also change the other. If you want to make a deep copy, use
5194
QDomEntity& QDomEntity::operator= (const QDomEntity& x)
5196
return (QDomEntity&) QDomNode::operator=(x);
5200
\fn QDomNode::NodeType QDomEntity::nodeType() const
5202
Returns \c EntityNode.
5206
Returns the public identifier associated with this entity. If the
5207
public identifier was not specified an empty string is returned.
5209
QString QDomEntity::publicId() const
5217
Returns the system identifier associated with this entity. If the
5218
system identifier was not specified an empty string is returned.
5220
QString QDomEntity::systemId() const
5228
For unparsed entities this function returns the name of the
5229
notation for the entity. For parsed entities this function returns
5232
QString QDomEntity::notationName() const
5236
return IMPL->m_notationName;
5241
/**************************************************************
5243
* QDomEntityReferencePrivate
5245
**************************************************************/
5247
QDomEntityReferencePrivate::QDomEntityReferencePrivate(QDomDocumentPrivate* d, QDomNodePrivate* parent, const QString& aname)
5248
: QDomNodePrivate(d, parent)
5253
QDomEntityReferencePrivate::QDomEntityReferencePrivate(QDomNodePrivate* n, bool deep)
5254
: QDomNodePrivate(n, deep)
5258
QDomNodePrivate* QDomEntityReferencePrivate::cloneNode(bool deep)
5260
QDomNodePrivate* p = new QDomEntityReferencePrivate(this, deep);
5261
// We are not interested in this node
5266
void QDomEntityReferencePrivate::save(QTextStream& s, int, int) const
5268
s << "&" << name << ";";
5271
/**************************************************************
5273
* QDomEntityReference
5275
**************************************************************/
5277
#define IMPL ((QDomEntityReferencePrivate*)impl)
5280
\class QDomEntityReference
5282
\brief The QDomEntityReference class represents an XML entity reference.
5287
A QDomEntityReference object may be inserted into the DOM tree
5288
when an entity reference is in the source document, or when the
5289
user wishes to insert an entity reference.
5291
Note that character references and references to predefined
5292
entities are expanded by the XML processor so that characters are
5293
represented by their Unicode equivalent rather than by an entity
5296
Moreover, the XML processor may completely expand references to
5297
entities while building the DOM tree, instead of providing
5298
QDomEntityReference objects.
5300
If it does provide such objects, then for a given entity reference
5301
node, it may be that there is no entity node representing the
5302
referenced entity; but if such an entity exists, then the child
5303
list of the entity reference node is the same as that of the
5304
entity node. As with the entity node, all descendents of the
5305
entity reference are read-only.
5307
For further information about the Document Object Model see
5308
\l{http://www.w3.org/TR/REC-DOM-Level-1/}{Level 1} and
5309
\l{http://www.w3.org/TR/DOM-Level-2-Core/}{Level 2 Core}.
5310
For a more general introduction of the DOM implementation see the
5311
QDomDocument documentation.
5315
Constructs an empty entity reference. Use
5316
QDomDocument::createEntityReference() to create a entity reference
5319
QDomEntityReference::QDomEntityReference()
5325
Constructs a copy of \a x.
5327
The data of the copy is shared (shallow copy): modifying one node
5328
will also change the other. If you want to make a deep copy, use
5331
QDomEntityReference::QDomEntityReference(const QDomEntityReference& x)
5336
QDomEntityReference::QDomEntityReference(QDomEntityReferencePrivate* n)
5342
Assigns \a x to this entity reference.
5344
The data of the copy is shared (shallow copy): modifying one node
5345
will also change the other. If you want to make a deep copy, use
5348
QDomEntityReference& QDomEntityReference::operator= (const QDomEntityReference& x)
5350
return (QDomEntityReference&) QDomNode::operator=(x);
5354
\fn QDomNode::NodeType QDomEntityReference::nodeType() const
5356
Returns \c EntityReference.
5361
/**************************************************************
5363
* QDomProcessingInstructionPrivate
5365
**************************************************************/
5367
QDomProcessingInstructionPrivate::QDomProcessingInstructionPrivate(QDomDocumentPrivate* d,
5368
QDomNodePrivate* parent, const QString& target, const QString& data)
5369
: QDomNodePrivate(d, parent)
5375
QDomProcessingInstructionPrivate::QDomProcessingInstructionPrivate(QDomProcessingInstructionPrivate* n, bool deep)
5376
: QDomNodePrivate(n, deep)
5381
QDomNodePrivate* QDomProcessingInstructionPrivate::cloneNode(bool deep)
5383
QDomNodePrivate* p = new QDomProcessingInstructionPrivate(this, deep);
5384
// We are not interested in this node
5389
void QDomProcessingInstructionPrivate::save(QTextStream& s, int, int) const
5391
s << "<?" << name << " " << value << "?>" << endl;
5394
/**************************************************************
5396
* QDomProcessingInstruction
5398
**************************************************************/
5400
#define IMPL ((QDomProcessingInstructionPrivate*)impl)
5403
\class QDomProcessingInstruction
5405
\brief The QDomProcessingInstruction class represents an XML processing
5411
Processing instructions are used in XML to keep processor-specific
5412
information in the text of the document.
5414
The content of the processing instruction is retrieved with data()
5415
and set with setData(). The processing instruction's target is
5416
retrieved with target().
5418
For further information about the Document Object Model see
5419
\l{http://www.w3.org/TR/REC-DOM-Level-1/}{Level 1} and
5420
\l{http://www.w3.org/TR/DOM-Level-2-Core/}{Level 2 Core}.
5421
For a more general introduction of the DOM implementation see the
5422
QDomDocument documentation.
5426
Constructs an empty processing instruction. Use
5427
QDomDocument::createProcessingInstruction() to create a processing
5428
instruction with content.
5430
QDomProcessingInstruction::QDomProcessingInstruction()
5436
Constructs a copy of \a x.
5438
The data of the copy is shared (shallow copy): modifying one node
5439
will also change the other. If you want to make a deep copy, use
5442
QDomProcessingInstruction::QDomProcessingInstruction(const QDomProcessingInstruction& x)
5447
QDomProcessingInstruction::QDomProcessingInstruction(QDomProcessingInstructionPrivate* n)
5453
Assigns \a x to this processing instruction.
5455
The data of the copy is shared (shallow copy): modifying one node
5456
will also change the other. If you want to make a deep copy, use
5459
QDomProcessingInstruction& QDomProcessingInstruction::operator= (const QDomProcessingInstruction& x)
5461
return (QDomProcessingInstruction&) QDomNode::operator=(x);
5465
\fn QDomNode::NodeType QDomProcessingInstruction::nodeType() const
5467
Returns \c ProcessingInstructionNode.
5471
Returns the target of this processing instruction.
5475
QString QDomProcessingInstruction::target() const
5479
return impl->nodeName();
5483
Returns the content of this processing instruction.
5485
\sa setData() target()
5487
QString QDomProcessingInstruction::data() const
5491
return impl->nodeValue();
5495
Sets the data contained in the processing instruction to \a d.
5499
void QDomProcessingInstruction::setData(const QString& d)
5503
impl->setNodeValue(d);
5508
/**************************************************************
5510
* QDomDocumentPrivate
5512
**************************************************************/
5514
QDomDocumentPrivate::QDomDocumentPrivate()
5515
: QDomNodePrivate(0)
5517
impl = new QDomImplementationPrivate;
5518
type = new QDomDocumentTypePrivate(this, this);
5523
QDomDocumentPrivate::QDomDocumentPrivate(const QString& aname)
5524
: QDomNodePrivate(0)
5526
impl = new QDomImplementationPrivate;
5527
type = new QDomDocumentTypePrivate(this, this);
5533
QDomDocumentPrivate::QDomDocumentPrivate(QDomDocumentTypePrivate* dt)
5534
: QDomNodePrivate(0)
5536
impl = new QDomImplementationPrivate;
5541
type = new QDomDocumentTypePrivate(this, this);
5547
QDomDocumentPrivate::QDomDocumentPrivate(QDomDocumentPrivate* n, bool deep)
5548
: QDomNodePrivate(n, deep)
5550
impl = n->impl->clone();
5551
// Reference count is down to 0, so we set it to 1 here.
5553
type = (QDomDocumentTypePrivate*)n->type->cloneNode();
5554
type->setParent(this);
5555
// Reference count is down to 0, so we set it to 1 here.
5559
QDomDocumentPrivate::~QDomDocumentPrivate()
5561
if (!impl->ref.deref())
5563
if (!type->ref.deref())
5567
void QDomDocumentPrivate::clear()
5569
if (!impl->ref.deref())
5571
if (!type->ref.deref())
5575
QDomNodePrivate::clear();
5578
bool QDomDocumentPrivate::setContent(QXmlInputSource *source, bool namespaceProcessing, QString *errorMsg, int *errorLine, int *errorColumn)
5580
QXmlSimpleReader reader;
5581
reader.setFeature("http://xml.org/sax/features/namespaces", namespaceProcessing);
5582
reader.setFeature("http://xml.org/sax/features/namespace-prefixes", !namespaceProcessing);
5583
reader.setFeature("http://trolltech.com/xml/features/report-whitespace-only-CharData", false);
5585
return setContent(source, &reader, errorMsg, errorLine, errorColumn);
5588
bool QDomDocumentPrivate::setContent(QXmlInputSource *source, QXmlReader *reader, QString *errorMsg, int *errorLine, int *errorColumn)
5591
impl = new QDomImplementationPrivate;
5592
type = new QDomDocumentTypePrivate(this, this);
5594
bool namespaceProcessing = reader->feature("http://xml.org/sax/features/namespaces")
5595
&& !reader->feature("http://xml.org/sax/features/namespace-prefixes");
5597
QDomHandler hnd(this, namespaceProcessing);
5598
reader->setContentHandler(&hnd);
5599
reader->setErrorHandler(&hnd);
5600
reader->setLexicalHandler(&hnd);
5601
reader->setDeclHandler(&hnd);
5602
reader->setDTDHandler(&hnd);
5604
if (!reader->parse(source)) {
5606
*errorMsg = hnd.errorMsg;
5608
*errorLine = hnd.errorLine;
5610
*errorColumn = hnd.errorColumn;
5617
QDomNodePrivate* QDomDocumentPrivate::cloneNode(bool deep)
5619
QDomNodePrivate *p = new QDomDocumentPrivate(this, deep);
5620
// We are not interested in this node
5625
QDomElementPrivate* QDomDocumentPrivate::documentElement()
5627
QDomNodePrivate *p = first;
5628
while (p && !p->isElement())
5631
return static_cast<QDomElementPrivate *>(p);
5634
QDomElementPrivate* QDomDocumentPrivate::createElement(const QString &tagName)
5636
QDomElementPrivate *e = new QDomElementPrivate(this, 0, tagName);
5641
QDomElementPrivate* QDomDocumentPrivate::createElementNS(const QString &nsURI, const QString &qName)
5643
QDomElementPrivate *e = new QDomElementPrivate(this, 0, nsURI, qName);
5648
QDomDocumentFragmentPrivate* QDomDocumentPrivate::createDocumentFragment()
5650
QDomDocumentFragmentPrivate *f = new QDomDocumentFragmentPrivate(this, (QDomNodePrivate*)0);
5655
QDomTextPrivate* QDomDocumentPrivate::createTextNode(const QString &data)
5657
QDomTextPrivate *t = new QDomTextPrivate(this, 0, data);
5662
QDomCommentPrivate* QDomDocumentPrivate::createComment(const QString &data)
5664
QDomCommentPrivate *c = new QDomCommentPrivate(this, 0, data);
5669
QDomCDATASectionPrivate* QDomDocumentPrivate::createCDATASection(const QString &data)
5671
QDomCDATASectionPrivate *c = new QDomCDATASectionPrivate(this, 0, data);
5676
QDomProcessingInstructionPrivate* QDomDocumentPrivate::createProcessingInstruction(const QString &target,
5677
const QString &data)
5679
QDomProcessingInstructionPrivate *p = new QDomProcessingInstructionPrivate(this, 0, target, data);
5684
QDomAttrPrivate* QDomDocumentPrivate::createAttribute(const QString &aname)
5686
QDomAttrPrivate *a = new QDomAttrPrivate(this, 0, aname);
5691
QDomAttrPrivate* QDomDocumentPrivate::createAttributeNS(const QString &nsURI, const QString &qName)
5693
QDomAttrPrivate *a = new QDomAttrPrivate(this, 0, nsURI, qName);
5698
QDomEntityReferencePrivate* QDomDocumentPrivate::createEntityReference(const QString &aname)
5700
QDomEntityReferencePrivate *e = new QDomEntityReferencePrivate(this, 0, aname);
5705
QDomNodePrivate* QDomDocumentPrivate::importNode(const QDomNodePrivate *importedNode, bool deep)
5707
QDomNodePrivate *node = 0;
5708
switch (importedNode->nodeType()) {
5709
case QDomNode::AttributeNode:
5710
node = new QDomAttrPrivate((QDomAttrPrivate*)importedNode, true);
5712
case QDomNode::DocumentFragmentNode:
5713
node = new QDomDocumentFragmentPrivate((QDomDocumentFragmentPrivate*)importedNode, deep);
5715
case QDomNode::ElementNode:
5716
node = new QDomElementPrivate((QDomElementPrivate*)importedNode, deep);
5718
case QDomNode::EntityNode:
5719
node = new QDomEntityPrivate((QDomEntityPrivate*)importedNode, deep);
5721
case QDomNode::EntityReferenceNode:
5722
node = new QDomEntityReferencePrivate((QDomEntityReferencePrivate*)importedNode, false);
5724
case QDomNode::NotationNode:
5725
node = new QDomNotationPrivate((QDomNotationPrivate*)importedNode, deep);
5727
case QDomNode::ProcessingInstructionNode:
5728
node = new QDomProcessingInstructionPrivate((QDomProcessingInstructionPrivate*)importedNode, deep);
5730
case QDomNode::TextNode:
5731
node = new QDomTextPrivate((QDomTextPrivate*)importedNode, deep);
5733
case QDomNode::CDATASectionNode:
5734
node = new QDomCDATASectionPrivate((QDomCDATASectionPrivate*)importedNode, deep);
5736
case QDomNode::CommentNode:
5737
node = new QDomCommentPrivate((QDomCommentPrivate*)importedNode, deep);
5743
node->setOwnerDocument(this);
5744
// The QDomNode constructor increases the refcount, so deref first to
5745
// keep refcount balanced.
5751
void QDomDocumentPrivate::save(QTextStream& s, int, int indent) const
5755
QDomNodePrivate* n = first;
5756
if (n && n->isProcessingInstruction() && n->nodeName()=="xml") {
5757
// we have an XML declaration
5758
QString data = n->nodeValue();
5759
QRegExp encoding(QString::fromLatin1("encoding\\s*=\\s*((\"([^\"]*)\")|('([^']*)'))"));
5760
encoding.indexIn(data);
5761
QString enc = encoding.cap(3);
5762
if (enc.isEmpty()) {
5763
enc = encoding.cap(5);
5766
s.setCodec(QTextCodec::codecForName("UTF-8"));
5768
s.setCodec(QTextCodec::codecForName(enc.toLatin1().data()));
5770
s.setCodec(QTextCodec::codecForName("UTF-8"));
5772
s.setAutoDetectUnicode(true);
5775
if (!doc && !(n->isProcessingInstruction()&&n->nodeName()=="xml")) {
5776
// save doctype after XML declaration
5777
type->save(s, 0, indent);
5780
n->save(s, 0, indent);
5785
/**************************************************************
5789
**************************************************************/
5791
#define IMPL ((QDomDocumentPrivate*)impl)
5796
\brief The QDomDocument class represents an XML document.
5802
The QDomDocument class represents the entire XML document.
5803
Conceptually, it is the root of the document tree, and provides
5804
the primary access to the document's data.
5806
Since elements, text nodes, comments, processing instructions,
5807
etc., cannot exist outside the context of a document, the document
5808
class also contains the factory functions needed to create these
5809
objects. The node objects created have an ownerDocument() function
5810
which associates them with the document within whose context they
5811
were created. The DOM classes that will be used most often are
5812
QDomNode, QDomDocument, QDomElement and QDomText.
5814
The parsed XML is represented internally by a tree of objects that
5815
can be accessed using the various QDom classes. All QDom classes
5816
only \e reference objects in the internal tree. The internal
5817
objects in the DOM tree will get deleted once the last QDom
5818
object referencing them and the QDomDocument itself are deleted.
5820
Creation of elements, text nodes, etc. is done using the various
5821
factory functions provided in this class. Using the default
5822
constructors of the QDom classes will only result in empty
5823
objects that cannot be manipulated or inserted into the Document.
5825
The QDomDocument class has several functions for creating document
5826
data, for example, createElement(), createTextNode(),
5827
createComment(), createCDATASection(),
5828
createProcessingInstruction(), createAttribute() and
5829
createEntityReference(). Some of these functions have versions
5830
that support namespaces, i.e. createElementNS() and
5831
createAttributeNS(). The createDocumentFragment() function is used
5832
to hold parts of the document; this is useful for manipulating for
5835
The entire content of the document is set with setContent(). This
5836
function parses the string it is passed as an XML document and
5837
creates the DOM tree that represents the document. The root
5838
element is available using documentElement(). The textual
5839
representation of the document can be obtained using toString().
5841
It is possible to insert a node from another document into the
5842
document using importNode().
5844
You can obtain a list of all the elements that have a particular
5845
tag with elementsByTagName() or with elementsByTagNameNS().
5847
The QDom classes are typically used as follows:
5849
QDomDocument doc("mydocument");
5850
QFile file("mydocument.xml");
5851
if (!file.open(QIODevice::ReadOnly))
5853
if (!doc.setContent(&file)) {
5859
// print out the element names of all elements that are direct children
5860
// of the outermost element.
5861
QDomElement docElem = doc.documentElement();
5863
QDomNode n = docElem.firstChild();
5864
while(!n.isNull()) {
5865
QDomElement e = n.toElement(); // try to convert the node to an element.
5867
cout << e.tagName() << endl; // the node really is an element.
5869
n = n.nextSibling();
5872
// Here we append a new element to the end of the document
5873
QDomElement elem = doc.createElement("img");
5874
elem.setAttribute("src", "myimage.png");
5875
docElem.appendChild(elem);
5878
Once \c doc and \c elem go out of scope, the whole internal tree
5879
representing the XML document is deleted.
5881
To create a document using DOM use code like this:
5883
QDomDocument doc("MyML");
5884
QDomElement root = doc.createElement("MyML");
5885
doc.appendChild(root);
5887
QDomElement tag = doc.createElement("Greeting");
5888
root.appendChild(tag);
5890
QDomText t = doc.createTextNode("Hello World");
5893
QString xml = doc.toString();
5896
For further information about the Document Object Model see
5897
the Document Object Model (DOM)
5898
\l{http://www.w3.org/TR/REC-DOM-Level-1/}{Level 1} and
5899
\l{http://www.w3.org/TR/DOM-Level-2-Core/}{Level 2 Core}
5905
Constructs an empty document.
5907
QDomDocument::QDomDocument()
5909
impl = new QDomDocumentPrivate;
5913
Creates a document and sets the name of the document type to \a
5916
QDomDocument::QDomDocument(const QString& name)
5918
// We take over ownership
5919
impl = new QDomDocumentPrivate(name);
5923
Creates a document with the document type \a doctype.
5925
\sa QDomImplementation::createDocumentType()
5927
QDomDocument::QDomDocument(const QDomDocumentType& doctype)
5929
impl = new QDomDocumentPrivate((QDomDocumentTypePrivate*)(doctype.impl));
5933
Constructs a copy of \a x.
5935
The data of the copy is shared (shallow copy): modifying one node
5936
will also change the other. If you want to make a deep copy, use
5939
QDomDocument::QDomDocument(const QDomDocument& x)
5944
QDomDocument::QDomDocument(QDomDocumentPrivate* x)
5950
Assigns \a x to this DOM document.
5952
The data of the copy is shared (shallow copy): modifying one node
5953
will also change the other. If you want to make a deep copy, use
5956
QDomDocument& QDomDocument::operator= (const QDomDocument& x)
5958
return (QDomDocument&) QDomNode::operator=(x);
5962
Destroys the object and frees its resources.
5964
QDomDocument::~QDomDocument()
5971
This function reads the XML document from the string \a text.
5972
Since \a text is already a Unicode string, no encoding detection
5975
bool QDomDocument::setContent(const QString& text, bool namespaceProcessing, QString *errorMsg, int *errorLine, int *errorColumn)
5978
impl = new QDomDocumentPrivate;
5979
QXmlInputSource source;
5980
source.setData(text);
5981
return IMPL->setContent(&source, namespaceProcessing, errorMsg, errorLine, errorColumn);
5985
This function parses the XML document from the byte array \a
5986
data and sets it as the content of the document. It tries to
5987
detect the encoding of the document as required by the XML
5990
If \a namespaceProcessing is true, the parser recognizes
5991
namespaces in the XML file and sets the prefix name, local name
5992
and namespace URI to appropriate values. If \a namespaceProcessing
5993
is false, the parser does no namespace processing when it reads
5996
If a parse error occurs, the function returns false; otherwise it
5997
returns true. If a parse error occurs and \a errorMsg, \a
5998
errorLine and \a errorColumn are not 0, the error message is
5999
placed in \c{*}\a{errorMsg}, the line number \c{*}\a{errorLine} and the
6000
column number in \c{*}\a{errorColumn}.
6002
If \a namespaceProcessing is true, the function QDomNode::prefix()
6003
returns a string for all elements and attributes. It returns an
6004
empty string if the element or attribute has no prefix.
6006
If \a namespaceProcessing is false, the functions
6007
QDomNode::prefix(), QDomNode::localName() and
6008
QDomNode::namespaceURI() return an empty string.
6010
\sa QDomNode::namespaceURI() QDomNode::localName()
6011
QDomNode::prefix() QString::isNull() QString::isEmpty()
6013
bool QDomDocument::setContent(const QByteArray &data, bool namespaceProcessing, QString *errorMsg, int *errorLine, int *errorColumn)
6016
impl = new QDomDocumentPrivate;
6019
QXmlInputSource source(&buf);
6020
return IMPL->setContent(&source, namespaceProcessing, errorMsg, errorLine, errorColumn);
6026
This function reads the XML document from the IO device \a dev.
6028
bool QDomDocument::setContent(QIODevice* dev, bool namespaceProcessing, QString *errorMsg, int *errorLine, int *errorColumn)
6031
impl = new QDomDocumentPrivate;
6032
QXmlInputSource source(dev);
6033
return IMPL->setContent(&source, namespaceProcessing, errorMsg, errorLine, errorColumn);
6039
This function reads the XML document from the string \a text.
6040
Since \a text is already a Unicode string, no encoding detection
6043
No namespace processing is performed either.
6045
bool QDomDocument::setContent(const QString& text, QString *errorMsg, int *errorLine, int *errorColumn)
6047
return setContent(text, false, errorMsg, errorLine, errorColumn);
6053
This function reads the XML document from the byte array \a
6056
No namespace processing is performed.
6058
bool QDomDocument::setContent(const QByteArray& buffer, QString *errorMsg, int *errorLine, int *errorColumn )
6060
return setContent(buffer, false, errorMsg, errorLine, errorColumn);
6066
This function reads the XML document from the IO device \a dev.
6068
No namespace processing is performed.
6070
bool QDomDocument::setContent(QIODevice* dev, QString *errorMsg, int *errorLine, int *errorColumn )
6072
return setContent(dev, false, errorMsg, errorLine, errorColumn);
6078
This function reads the XML document from the QXmlInputSource \a source and
6079
parses it with the QXmlReader \a reader.
6081
This function doesn't change the features of the \a reader. If you want to
6082
use certain features for parsing you can use this function to set up the
6083
reader appropriately.
6085
\sa QXmlSimpleReader
6087
bool QDomDocument::setContent(QXmlInputSource *source, QXmlReader *reader, QString *errorMsg, int *errorLine, int *errorColumn )
6090
impl = new QDomDocumentPrivate;
6091
return IMPL->setContent(source, reader, errorMsg, errorLine, errorColumn);
6095
Converts the parsed document back to its textual representation.
6097
This function uses \a indent as the amount of space to indent
6100
QString QDomDocument::toString(int indent) const
6103
QTextStream s(&str, QIODevice::WriteOnly);
6109
Converts the parsed document back to its textual representation
6110
and returns a QByteArray containing the data encoded as UTF-8.
6112
This function uses \a indent as the amount of space to indent
6117
QByteArray QDomDocument::toByteArray(int indent) const
6119
// ### if there is an encoding specified in the xml declaration, this
6120
// encoding declaration should be changed to utf8
6121
return toString(indent).toUtf8();
6126
Returns the document type of this document.
6128
QDomDocumentType QDomDocument::doctype() const
6131
return QDomDocumentType();
6132
return QDomDocumentType(IMPL->doctype());
6136
Returns a QDomImplementation object.
6138
QDomImplementation QDomDocument::implementation() const
6141
return QDomImplementation();
6142
return QDomImplementation(IMPL->implementation());
6146
Returns the root element of the document.
6148
QDomElement QDomDocument::documentElement() const
6151
return QDomElement();
6152
return QDomElement(IMPL->documentElement());
6156
Creates a new element called \a tagName that can be inserted into
6157
the DOM tree, e.g. using QDomNode::appendChild().
6159
\sa createElementNS() QDomNode::appendChild() QDomNode::insertBefore()
6160
QDomNode::insertAfter()
6162
QDomElement QDomDocument::createElement(const QString& tagName)
6165
return QDomElement();
6166
return QDomElement(IMPL->createElement(tagName));
6170
Creates a new document fragment, that can be used to hold parts of
6171
the document, e.g. when doing complex manipulations of the
6174
QDomDocumentFragment QDomDocument::createDocumentFragment()
6177
return QDomDocumentFragment();
6178
return QDomDocumentFragment(IMPL->createDocumentFragment());
6182
Creates a text node for the string \a value that can be inserted
6183
into the document tree, e.g. using QDomNode::appendChild().
6185
\sa QDomNode::appendChild() QDomNode::insertBefore() QDomNode::insertAfter()
6187
QDomText QDomDocument::createTextNode(const QString& value)
6191
return QDomText(IMPL->createTextNode(value));
6195
Creates a new comment for the string \a value that can be inserted
6196
into the document, e.g. using QDomNode::appendChild().
6198
\sa QDomNode::appendChild() QDomNode::insertBefore() QDomNode::insertAfter()
6200
QDomComment QDomDocument::createComment(const QString& value)
6203
return QDomComment();
6204
return QDomComment(IMPL->createComment(value));
6208
Creates a new CDATA section for the string \a value that can be
6209
inserted into the document, e.g. using QDomNode::appendChild().
6211
\sa QDomNode::appendChild() QDomNode::insertBefore() QDomNode::insertAfter()
6213
QDomCDATASection QDomDocument::createCDATASection(const QString& value)
6216
return QDomCDATASection();
6217
return QDomCDATASection(IMPL->createCDATASection(value));
6221
Creates a new processing instruction that can be inserted into the
6222
document, e.g. using QDomNode::appendChild(). This function sets
6223
the target for the processing instruction to \a target and the
6226
\sa QDomNode::appendChild() QDomNode::insertBefore() QDomNode::insertAfter()
6228
QDomProcessingInstruction QDomDocument::createProcessingInstruction(const QString& target,
6229
const QString& data)
6232
return QDomProcessingInstruction();
6233
return QDomProcessingInstruction(IMPL->createProcessingInstruction(target, data));
6238
Creates a new attribute called \a name that can be inserted into
6239
an element, e.g. using QDomElement::setAttributeNode().
6241
\sa createAttributeNS()
6243
QDomAttr QDomDocument::createAttribute(const QString& name)
6247
return QDomAttr(IMPL->createAttribute(name));
6251
Creates a new entity reference called \a name that can be inserted
6252
into the document, e.g. using QDomNode::appendChild().
6254
\sa QDomNode::appendChild() QDomNode::insertBefore() QDomNode::insertAfter()
6256
QDomEntityReference QDomDocument::createEntityReference(const QString& name)
6259
return QDomEntityReference();
6260
return QDomEntityReference(IMPL->createEntityReference(name));
6264
Returns a QDomNodeList, that contains all the elements in the
6265
document with the name \a tagname. The order of the node list is
6266
the order they are encountered in a preorder traversal of the
6269
\sa elementsByTagNameNS() QDomElement::elementsByTagName()
6271
QDomNodeList QDomDocument::elementsByTagName(const QString& tagname) const
6273
return QDomNodeList(new QDomNodeListPrivate(impl, tagname));
6277
Imports the node \a importedNode from another document to this
6278
document. \a importedNode remains in the original document; this
6279
function creates a copy that can be used within this document.
6281
This function returns the imported node that belongs to this
6282
document. The returned node has no parent. It is not possible to
6283
import QDomDocument and QDomDocumentType nodes. In those cases
6284
this function returns a \link QDomNode::isNull() null node\endlink.
6286
If \a deep is true, this function imports not only the node \a
6287
importedNode but its whole subtree; if it is false, only the \a
6288
importedNode is imported. The argument \a deep has no effect on
6289
QDomAttr and QDomEntityReference nodes, since the descendents of
6290
QDomAttr nodes are always imported and those of
6291
QDomEntityReference nodes are never imported.
6293
The behavior of this function is slightly different depending on
6296
\header \i Node Type \i Behavior
6298
\i The owner element is set to 0 and the specified flag is
6299
set to true in the generated attribute. The whole subtree
6300
of \a importedNode is always imported for attribute nodes:
6301
\a deep has no effect.
6302
\row \i QDomDocument
6303
\i Document nodes cannot be imported.
6304
\row \i QDomDocumentFragment
6305
\i If \a deep is true, this function imports the whole
6306
document fragment; otherwise it only generates an empty
6308
\row \i QDomDocumentType
6309
\i Document type nodes cannot be imported.
6311
\i Attributes for which QDomAttr::specified() is true are
6312
also imported, other attributes are not imported. If \a
6313
deep is true, this function also imports the subtree of \a
6314
importedNode; otherwise it imports only the element node
6315
(and some attributes, see above).
6317
\i Entity nodes can be imported, but at the moment there is
6318
no way to use them since the document type is read-only in
6320
\row \i QDomEntityReference
6321
\i Descendents of entity reference nodes are never imported:
6322
\a deep has no effect.
6323
\row \i QDomNotation
6324
\i Notation nodes can be imported, but at the moment there is
6325
no way to use them since the document type is read-only in
6327
\row \i QDomProcessingInstruction
6328
\i The target and value of the processing instruction is
6329
copied to the new node.
6331
\i The text is copied to the new node.
6332
\row \i QDomCDATASection
6333
\i The text is copied to the new node.
6335
\i The text is copied to the new node.
6338
\sa QDomElement::setAttribute() QDomNode::insertBefore()
6339
QDomNode::insertAfter() QDomNode::replaceChild() QDomNode::removeChild()
6340
QDomNode::appendChild()
6342
QDomNode QDomDocument::importNode(const QDomNode& importedNode, bool deep)
6346
return QDomNode(IMPL->importNode(importedNode.impl, deep));
6350
Creates a new element with namespace support that can be inserted
6351
into the DOM tree. The name of the element is \a qName and the
6352
namespace URI is \a nsURI. This function also sets
6353
QDomNode::prefix() and QDomNode::localName() to appropriate values
6354
(depending on \a qName).
6358
QDomElement QDomDocument::createElementNS(const QString& nsURI, const QString& qName)
6361
return QDomElement();
6362
return QDomElement(IMPL->createElementNS(nsURI, qName));
6366
Creates a new attribute with namespace support that can be
6367
inserted into an element. The name of the attribute is \a qName
6368
and the namespace URI is \a nsURI. This function also sets
6369
QDomNode::prefix() and QDomNode::localName() to appropriate values
6370
(depending on \a qName).
6372
\sa createAttribute()
6374
QDomAttr QDomDocument::createAttributeNS(const QString& nsURI, const QString& qName)
6378
return QDomAttr(IMPL->createAttributeNS(nsURI, qName));
6382
Returns a QDomNodeList that contains all the elements in the
6383
document with the local name \a localName and a namespace URI of
6384
\a nsURI. The order of the node list is the order they are
6385
encountered in a preorder traversal of the element tree.
6387
\sa elementsByTagName() QDomElement::elementsByTagNameNS()
6389
QDomNodeList QDomDocument::elementsByTagNameNS(const QString& nsURI, const QString& localName)
6391
return QDomNodeList(new QDomNodeListPrivate(impl, nsURI, localName));
6395
Returns the element whose ID is equal to \a elementId. If no
6396
element with the ID was found, this function returns a \link
6397
QDomNode::isNull() null element\endlink.
6399
Since the QDomClasses do not know which attributes are element
6400
IDs, this function returns always a \link QDomNode::isNull() null
6401
element\endlink. This may change in a future version.
6403
QDomElement QDomDocument::elementById(const QString& /*elementId*/)
6405
return QDomElement();
6409
\fn QDomNode::NodeType QDomDocument::nodeType() const
6411
Returns \c DocumentNode.
6416
/**************************************************************
6418
* Node casting functions
6420
**************************************************************/
6423
Converts a QDomNode into a QDomAttr. If the node is not an
6424
attribute, the returned object will be \link QDomNode::isNull()
6429
QDomAttr QDomNode::toAttr() const
6431
if (impl && impl->isAttr())
6432
return QDomAttr(((QDomAttrPrivate*)impl));
6437
Converts a QDomNode into a QDomCDATASection. If the node is not a
6438
CDATA section, the returned object will be \link
6439
QDomNode::isNull() null\endlink.
6441
\sa isCDATASection()
6443
QDomCDATASection QDomNode::toCDATASection() const
6445
if (impl && impl->isCDATASection())
6446
return QDomCDATASection(((QDomCDATASectionPrivate*)impl));
6447
return QDomCDATASection();
6451
Converts a QDomNode into a QDomDocumentFragment. If the node is
6452
not a document fragment the returned object will be \link
6453
QDomNode::isNull() null\endlink.
6455
\sa isDocumentFragment()
6457
QDomDocumentFragment QDomNode::toDocumentFragment() const
6459
if (impl && impl->isDocumentFragment())
6460
return QDomDocumentFragment(((QDomDocumentFragmentPrivate*)impl));
6461
return QDomDocumentFragment();
6465
Converts a QDomNode into a QDomDocument. If the node is not a
6466
document the returned object will be \link QDomNode::isNull()
6471
QDomDocument QDomNode::toDocument() const
6473
if (impl && impl->isDocument())
6474
return QDomDocument(((QDomDocumentPrivate*)impl));
6475
return QDomDocument();
6479
Converts a QDomNode into a QDomDocumentType. If the node is not a
6480
document type the returned object will be \link QDomNode::isNull()
6483
\sa isDocumentType()
6485
QDomDocumentType QDomNode::toDocumentType() const
6487
if (impl && impl->isDocumentType())
6488
return QDomDocumentType(((QDomDocumentTypePrivate*)impl));
6489
return QDomDocumentType();
6493
Converts a QDomNode into a QDomElement. If the node is not an
6494
element the returned object will be \link QDomNode::isNull()
6499
QDomElement QDomNode::toElement() const
6501
if (impl && impl->isElement())
6502
return QDomElement(((QDomElementPrivate*)impl));
6503
return QDomElement();
6507
Converts a QDomNode into a QDomEntityReference. If the node is not
6508
an entity reference, the returned object will be \link
6509
QDomNode::isNull() null\endlink.
6511
\sa isEntityReference()
6513
QDomEntityReference QDomNode::toEntityReference() const
6515
if (impl && impl->isEntityReference())
6516
return QDomEntityReference(((QDomEntityReferencePrivate*)impl));
6517
return QDomEntityReference();
6521
Converts a QDomNode into a QDomText. If the node is not a text,
6522
the returned object will be \link QDomNode::isNull() null\endlink.
6526
QDomText QDomNode::toText() const
6528
if (impl && impl->isText())
6529
return QDomText(((QDomTextPrivate*)impl));
6534
Converts a QDomNode into a QDomEntity. If the node is not an
6535
entity the returned object will be \link QDomNode::isNull()
6540
QDomEntity QDomNode::toEntity() const
6542
if (impl && impl->isEntity())
6543
return QDomEntity(((QDomEntityPrivate*)impl));
6544
return QDomEntity();
6548
Converts a QDomNode into a QDomNotation. If the node is not a
6549
notation the returned object will be \link QDomNode::isNull()
6554
QDomNotation QDomNode::toNotation() const
6556
if (impl && impl->isNotation())
6557
return QDomNotation(((QDomNotationPrivate*)impl));
6558
return QDomNotation();
6562
Converts a QDomNode into a QDomProcessingInstruction. If the node
6563
is not a processing instruction the returned object will be \link
6564
QDomNode::isNull() null\endlink.
6566
\sa isProcessingInstruction()
6568
QDomProcessingInstruction QDomNode::toProcessingInstruction() const
6570
if (impl && impl->isProcessingInstruction())
6571
return QDomProcessingInstruction(((QDomProcessingInstructionPrivate*)impl));
6572
return QDomProcessingInstruction();
6576
Converts a QDomNode into a QDomCharacterData. If the node is not a
6577
character data node the returned object will be \link
6578
QDomNode::isNull() null\endlink.
6580
\sa isCharacterData()
6582
QDomCharacterData QDomNode::toCharacterData() const
6584
if (impl && impl->isCharacterData())
6585
return QDomCharacterData(((QDomCharacterDataPrivate*)impl));
6586
return QDomCharacterData();
6590
Converts a QDomNode into a QDomComment. If the node is not a
6591
comment the returned object will be \link QDomNode::isNull()
6596
QDomComment QDomNode::toComment() const
6598
if (impl && impl->isComment())
6599
return QDomComment(((QDomCommentPrivate*)impl));
6600
return QDomComment();
6603
/**************************************************************
6607
**************************************************************/
6609
QDomHandler::QDomHandler(QDomDocumentPrivate* adoc, bool namespaceProcessing)
6614
nsProcessing = namespaceProcessing;
6617
QDomHandler::~QDomHandler()
6621
bool QDomHandler::endDocument()
6623
// ### is this really necessary? (rms)
6629
bool QDomHandler::startDTD(const QString& name, const QString& publicId, const QString& systemId)
6631
doc->doctype()->name = name;
6632
doc->doctype()->publicId = publicId;
6633
doc->doctype()->systemId = systemId;
6637
bool QDomHandler::startElement(const QString& nsURI, const QString&, const QString& qName, const QXmlAttributes& atts)
6642
n = doc->createElementNS(nsURI, qName);
6644
n = doc->createElement(qName);
6646
node->appendChild(n);
6650
for (int i=0; i<atts.length(); i++)
6653
((QDomElementPrivate*)node)->setAttributeNS(atts.uri(i), atts.qName(i), atts.value(i));
6655
((QDomElementPrivate*)node)->setAttribute(atts.qName(i), atts.value(i));
6662
bool QDomHandler::endElement(const QString&, const QString&, const QString&)
6666
node = node->parent();
6671
bool QDomHandler::characters(const QString& ch)
6673
// No text as child of some document
6678
node->appendChild(doc->createCDATASection(ch));
6679
} else if (!entityName.isEmpty()) {
6680
QDomEntityPrivate* e = new QDomEntityPrivate(doc, 0, entityName,
6681
QString(), QString(), QString());
6683
doc->doctype()->appendChild(e);
6684
node->appendChild(doc->createEntityReference(entityName));
6686
node->appendChild(doc->createTextNode(ch));
6692
bool QDomHandler::processingInstruction(const QString& target, const QString& data)
6694
node->appendChild(doc->createProcessingInstruction(target, data));
6698
bool QDomHandler::skippedEntity(const QString& name)
6700
node->appendChild(doc->createEntityReference(name));
6704
bool QDomHandler::fatalError(const QXmlParseException& exception)
6706
errorMsg = exception.message();
6707
errorLine = exception.lineNumber();
6708
errorColumn = exception.columnNumber();
6709
return QXmlDefaultHandler::fatalError(exception);
6712
bool QDomHandler::startCDATA()
6718
bool QDomHandler::endCDATA()
6724
bool QDomHandler::startEntity(const QString &name)
6730
bool QDomHandler::endEntity(const QString &)
6736
bool QDomHandler::comment(const QString& ch)
6738
node->appendChild(doc->createComment(ch));
6742
bool QDomHandler::unparsedEntityDecl(const QString &name, const QString &publicId, const QString &systemId, const QString ¬ationName)
6744
QDomEntityPrivate* e = new QDomEntityPrivate(doc, 0, name,
6745
publicId, systemId, notationName);
6746
doc->doctype()->appendChild(e);
6750
bool QDomHandler::externalEntityDecl(const QString &name, const QString &publicId, const QString &systemId)
6752
return unparsedEntityDecl(name, publicId, systemId, QString());
6755
bool QDomHandler::notationDecl(const QString & name, const QString & publicId, const QString & systemId)
6757
QDomNotationPrivate* n = new QDomNotationPrivate(doc, 0, name, publicId, systemId);
6758
doc->doctype()->appendChild(n);