1QDomNode(3qt) QDomNode(3qt)
2
3
4
6 QDomNode - The base class for all the nodes in a DOM tree
7
9 All the functions in this class are reentrant when Qt is built with
10 thread support.</p>
11
12 #include <qdom.h>
13
14 Inherited by QDomDocumentType, QDomDocument, QDomDocumentFragment,
15 QDomCharacterData, QDomAttr, QDomElement, QDomNotation, QDomEntity,
16 QDomEntityReference, and QDomProcessingInstruction.
17
18 Public Members
19 enum NodeType { ElementNode = 1, AttributeNode = 2, TextNode = 3,
20 CDATASectionNode = 4, EntityReferenceNode = 5, EntityNode = 6,
21 ProcessingInstructionNode = 7, CommentNode = 8, DocumentNode = 9,
22 DocumentTypeNode = 10, DocumentFragmentNode = 11, NotationNode =
23 12, BaseNode = 21, CharacterDataNode = 22 }
24 QDomNode ()
25 QDomNode ( const QDomNode & n )
26 QDomNode & operator= ( const QDomNode & n )
27 bool operator== ( const QDomNode & n ) const
28 bool operator!= ( const QDomNode & n ) const
29 virtual ~QDomNode ()
30 virtual QDomNode insertBefore ( const QDomNode & newChild, const
31 QDomNode & refChild )
32 virtual QDomNode insertAfter ( const QDomNode & newChild, const
33 QDomNode & refChild )
34 virtual QDomNode replaceChild ( const QDomNode & newChild, const
35 QDomNode & oldChild )
36 virtual QDomNode removeChild ( const QDomNode & oldChild )
37 virtual QDomNode appendChild ( const QDomNode & newChild )
38 virtual bool hasChildNodes () const
39 virtual QDomNode cloneNode ( bool deep = TRUE ) const
40 virtual void normalize ()
41 virtual bool isSupported ( const QString & feature, const QString &
42 version ) const
43 virtual QString nodeName () const
44 virtual QDomNode::NodeType nodeType () const
45 virtual QDomNode parentNode () const
46 virtual QDomNodeList childNodes () const
47 virtual QDomNode firstChild () const
48 virtual QDomNode lastChild () const
49 virtual QDomNode previousSibling () const
50 virtual QDomNode nextSibling () const
51 virtual QDomNamedNodeMap attributes () const
52 virtual QDomDocument ownerDocument () const
53 virtual QString namespaceURI () const
54 virtual QString localName () const
55 virtual bool hasAttributes () const
56 virtual QString nodeValue () const
57 virtual void setNodeValue ( const QString & v )
58 virtual QString prefix () const
59 virtual void setPrefix ( const QString & pre )
60 virtual bool isAttr () const
61 virtual bool isCDATASection () const
62 virtual bool isDocumentFragment () const
63 virtual bool isDocument () const
64 virtual bool isDocumentType () const
65 virtual bool isElement () const
66 virtual bool isEntityReference () const
67 virtual bool isText () const
68 virtual bool isEntity () const
69 virtual bool isNotation () const
70 virtual bool isProcessingInstruction () const
71 virtual bool isCharacterData () const
72 virtual bool isComment () const
73 QDomNode namedItem ( const QString & name ) const
74 bool isNull () const
75 void clear ()
76 QDomAttr toAttr ()
77 QDomCDATASection toCDATASection ()
78 QDomDocumentFragment toDocumentFragment ()
79 QDomDocument toDocument ()
80 QDomDocumentType toDocumentType ()
81 QDomElement toElement ()
82 QDomEntityReference toEntityReference ()
83 QDomText toText ()
84 QDomEntity toEntity ()
85 QDomNotation toNotation ()
86 QDomProcessingInstruction toProcessingInstruction ()
87 QDomCharacterData toCharacterData ()
88 QDomComment toComment ()
89 void save ( QTextStream & str, int indent ) const
90
92 QTextStream & operator<< ( QTextStream & str, const QDomNode & node )
93
95 The QDomNode class is the base class for all the nodes in a DOM tree.
96
97 Many functions in the DOM return a QDomNode.
98
99 You can find out the type of a node using isAttr(), isCDATASection(),
100 isDocumentFragment(), isDocument(), isDocumentType(), isElement(),
101 isEntityReference(), isText(), isEntity(), isNotation(),
102 isProcessingInstruction(), isCharacterData() and isComment().
103
104 A QDomNode can be converted into one of its subclasses using toAttr(),
105 toCDATASection(), toDocumentFragment(), toDocument(), toDocumentType(),
106 toElement(), toEntityReference(), toText(), toEntity(), toNotation(),
107 toProcessingInstruction(), toCharacterData() or toComment(). You can
108 convert a node to a null node with clear().
109
110 Copies of the QDomNode class share their data using explicit sharing.
111 This means that modifying one node will change all copies. This is
112 especially useful in combination with functions which return a
113 QDomNode, e.g. firstChild(). You can make an independent (deep) copy of
114 the node with cloneNode().
115
116 Nodes are inserted with insertBefore(), insertAfter() or appendChild().
117 You can replace one node with another using replaceChild() and remove a
118 node with removeChild().
119
120 To traverse nodes use firstChild() to get a node's first child (if
121 any), and nextSibling() to traverse. QDomNode also provides
122 lastChild(), previousSibling() and parentNode(). To find the first
123 child node with a particular node name use namedItem().
124
125 To find out if a node has children use hasChildNodes() and to get a
126 list of all of a node's children use childNodes().
127
128 The node's name and value (the meaning of which varies depending on its
129 type) is returned by nodeName() and nodeValue() respectively. The
130 node's type is returned by nodeType(). The node's value can be set with
131 setNodeValue().
132
133 The document to which the node belongs is returned by ownerDocument().
134
135 Adjacent QDomText nodes can be merged into a single node with
136 normalize().
137
138 QDomElement nodes have attributes which can be retrieved with
139 attributes().
140
141 QDomElement and QDomAttr nodes can have namespaces which can be
142 retrieved with namespaceURI(). Their local name is retrieved with
143 localName(), and their prefix with prefix(). The prefix can be set with
144 setPrefix().
145
146 You can write the XML representation of the node to a text stream with
147 save().
148
149 The following example looks for the first element in an XML document
150 and prints the names of all the elements that are its direct children.
151
152 QDomDocument d;
153 d.setContent( someXML );
154 QDomNode n = d.firstChild();
155 while ( !n.isNull() ) {
156 if ( n.isElement() ) {
157 QDomElement e = n.toElement();
158 cout << "Element name: " << e.tagName() << endl;
159 break;
160 }
161 n = n.nextSibling();
162 }
163
164 For further information about the Document Object Model see
165 http://www.w3.org/TR/REC-DOM-Level-1/ and http://www.w3.org/TR/DOM-
166 Level-2-Core/. For a more general introduction of the DOM
167 implementation see the QDomDocument documentation.
168
169 See also XML.
170
171 Member Type Documentation
173 This enum defines the type of the node:
174
175 QDomNode::ElementNode
176
177 QDomNode::AttributeNode
178
179 QDomNode::TextNode
180
181 QDomNode::CDATASectionNode
182
183 QDomNode::EntityReferenceNode
184
185 QDomNode::EntityNode
186
187 QDomNode::ProcessingInstructionNode
188
189 QDomNode::CommentNode
190
191 QDomNode::DocumentNode
192
193 QDomNode::DocumentTypeNode
194
195 QDomNode::DocumentFragmentNode
196
197 QDomNode::NotationNode
198
199 QDomNode::BaseNode - A QDomNode object, i.e. not a QDomNode subclass.
200
201 QDomNode::CharacterDataNode
202
205 Constructs a null node.
206
208 Constructs a copy of n.
209
210 The data of the copy is shared (shallow copy): modifying one node will
211 also change the other. If you want to make a deep copy, use
212 cloneNode().
213
215 Destroys the object and frees its resources.
216
218 Appends newChild as the node's last child.
219
220 If newChild is the child of another node, it is reparented to this
221 node. If newChild is a child of this node, then its position in the
222 list of children is changed.
223
224 If newChild is a QDomDocumentFragment, then the children of the
225 fragment are removed from the fragment and appended.
226
227 Returns a new reference to newChild.
228
229 See also insertBefore(), insertAfter(), replaceChild(), and
230 removeChild().
231
233 Returns a named node map of all attributes. Attributes are only
234 provided for QDomElements.
235
236 Changing the attributes in the map will also change the attributes of
237 this QDomNode.
238
239 Reimplemented in QDomElement.
240
242 Returns a list of all direct child nodes.
243
244 Most often you will call this function on a QDomElement object.
245
246 For example, if the XML document looks like this:
247
248 <body>
249 <h1>Heading</h1>
250 <p>Hello <b>you</b></p>
251 </body>
252 Then the list of child nodes for the "body"-element will contain the
253 node created by the <h1> tag and the node created by the <p> tag.
254
255 The nodes in the list are not copied; so changing the nodes in the list
256 will also change the children of this node.
257
258 See also firstChild() and lastChild().
259
261 Converts the node into a null node; if it was not a null node before,
262 its type and contents are deleted.
263
264 See also isNull().
265
267 Creates a deep (not shallow) copy of the QDomNode.
268
269 If deep is TRUE, then the cloning is done recursively which means that
270 all the node's children are deep copied too. If deep is FALSE only the
271 node itself is copied and the copy will have no child nodes.
272
274 Returns the first child of the node. If there is no child node, a null
275 node is returned. Changing the returned node will also change the node
276 in the document tree.
277
278 See also lastChild() and childNodes().
279
280 Example: xml/outliner/outlinetree.cpp.
281
283 Returns TRUE if the node has attributes; otherwise returns FALSE.
284
285 See also attributes().
286
288 Returns TRUE if the node has one or more children; otherwise returns
289 FALSE.
290
292 refChild ) [virtual]
293 Inserts the node newChild after the child node refChild. refChild must
294 be a direct child of this node. If refChild is null then newChild is
295 appended as this node's last child.
296
297 If newChild is the child of another node, it is reparented to this
298 node. If newChild is a child of this node, then its position in the
299 list of children is changed.
300
301 If newChild is a QDomDocumentFragment, then the children of the
302 fragment are removed from the fragment and inserted after refChild.
303
304 Returns a new reference to newChild on success or a null node on
305 failure.
306
307 See also insertBefore(), replaceChild(), removeChild(), and
308 appendChild().
309
311 refChild ) [virtual]
312 Inserts the node newChild before the child node refChild. refChild must
313 be a direct child of this node. If refChild is null then newChild is
314 inserted as the node's first child.
315
316 If newChild is the child of another node, it is reparented to this
317 node. If newChild is a child of this node, then its position in the
318 list of children is changed.
319
320 If newChild is a QDomDocumentFragment, then the children of the
321 fragment are removed from the fragment and inserted before refChild.
322
323 Returns a new reference to newChild on success or a null node on
324 failure.
325
326 See also insertAfter(), replaceChild(), removeChild(), and
327 appendChild().
328
330 Returns TRUE if the node is an attribute; otherwise returns FALSE.
331
332 If this function returns TRUE, it does not imply that this object is a
333 QDomAttribute; you can get the QDomAttribute with toAttribute().
334
335 See also toAttr().
336
337 Reimplemented in QDomAttr.
338
340 Returns TRUE if the node is a CDATA section; otherwise returns FALSE.
341
342 If this function returns TRUE, it does not imply that this object is a
343 QDomCDATASection; you can get the QDomCDATASection with
344 toCDATASection().
345
346 See also toCDATASection().
347
348 Reimplemented in QDomCDATASection.
349
351 Returns TRUE if the node is a character data node; otherwise returns
352 FALSE.
353
354 If this function returns TRUE, it does not imply that this object is a
355 QDomCharacterData; you can get the QDomCharacterData with
356 toCharacterData().
357
358 See also toCharacterData().
359
360 Reimplemented in QDomCharacterData.
361
363 Returns TRUE if the node is a comment; otherwise returns FALSE.
364
365 If this function returns TRUE, it does not imply that this object is a
366 QDomComment; you can get the QDomComment with toComment().
367
368 See also toComment().
369
370 Reimplemented in QDomComment.
371
373 Returns TRUE if the node is a document; otherwise returns FALSE.
374
375 If this function returns TRUE, it does not imply that this object is a
376 QDomDocument; you can get the QDomDocument with toDocument().
377
378 See also toDocument().
379
380 Reimplemented in QDomDocument.
381
383 Returns TRUE if the node is a document fragment; otherwise returns
384 FALSE.
385
386 If this function returns TRUE, it does not imply that this object is a
387 QDomDocumentFragment; you can get the QDomDocumentFragment with
388 toDocumentFragment().
389
390 See also toDocumentFragment().
391
392 Reimplemented in QDomDocumentFragment.
393
395 Returns TRUE if the node is a document type; otherwise returns FALSE.
396
397 If this function returns TRUE, it does not imply that this object is a
398 QDomDocumentType; you can get the QDomDocumentType with
399 toDocumentType().
400
401 See also toDocumentType().
402
403 Reimplemented in QDomDocumentType.
404
406 Returns TRUE if the node is an element; otherwise returns FALSE.
407
408 If this function returns TRUE, it does not imply that this object is a
409 QDomElement; you can get the QDomElement with toElement().
410
411 See also toElement().
412
413 Example: xml/outliner/outlinetree.cpp.
414
415 Reimplemented in QDomElement.
416
418 Returns TRUE if the node is an entity; otherwise returns FALSE.
419
420 If this function returns TRUE, it does not imply that this object is a
421 QDomEntity; you can get the QDomEntity with toEntity().
422
423 See also toEntity().
424
425 Reimplemented in QDomEntity.
426
428 Returns TRUE if the node is an entity reference; otherwise returns
429 FALSE.
430
431 If this function returns TRUE, it does not imply that this object is a
432 QDomEntityReference; you can get the QDomEntityReference with
433 toEntityReference().
434
435 See also toEntityReference().
436
437 Reimplemented in QDomEntityReference.
438
440 Returns TRUE if the node is a notation; otherwise returns FALSE.
441
442 If this function returns TRUE, it does not imply that this object is a
443 QDomNotation; you can get the QDomNotation with toNotation().
444
445 See also toNotation().
446
447 Reimplemented in QDomNotation.
448
450 Returns TRUE if this node is null (i.e. if it has no type or contents);
451 otherwise returns FALSE.
452
453 Example: xml/outliner/outlinetree.cpp.
454
456 Returns TRUE if the node is a processing instruction; otherwise returns
457 FALSE.
458
459 If this function returns TRUE, it does not imply that this object is a
460 QDomProcessingInstruction; you can get the QProcessingInstruction with
461 toProcessingInstruction().
462
463 See also toProcessingInstruction().
464
465 Reimplemented in QDomProcessingInstruction.
466
468 ) const [virtual]
469 Returns TRUE if the DOM implementation implements the feature feature
470 and this feature is supported by this node in the version version;
471 otherwise returns FALSE.
472
473 See also QDomImplementation::hasFeature().
474
476 Returns TRUE if the node is a text node; otherwise returns FALSE.
477
478 If this function returns TRUE, it does not imply that this object is a
479 QDomText; you can get the QDomText with toText().
480
481 See also toText().
482
483 Reimplemented in QDomText.
484
486 Returns the last child of the node. If there is no child node, a null
487 node is returned. Changing the returned node will also change the node
488 in the document tree.
489
490 See also firstChild() and childNodes().
491
493 If the node uses namespaces, this function returns the local name of
494 the node; otherwise it returns QString::null.
495
496 Only nodes of type ElementNode or AttributeNode can have namespaces. A
497 namespace must have been specified at creation time; it is not possible
498 to add a namespace afterwards.
499
500 See also prefix(), namespaceURI(), QDomDocument::createElementNS(), and
501 QDomDocument::createAttributeNS().
502
504 Returns the first direct child node for which nodeName() equals name.
505
506 If no such direct child exists, a null node is returned.
507
508 See also nodeName().
509
511 Returns the namespace URI of this node or QString::null if the node has
512 no namespace URI.
513
514 Only nodes of type ElementNode or AttributeNode can have namespaces. A
515 namespace URI must be specified at creation time and cannot be changed
516 later.
517
518 See also prefix(), localName(), QDomDocument::createElementNS(), and
519 QDomDocument::createAttributeNS().
520
522 Returns the next sibling in the document tree. Changing the returned
523 node will also change the node in the document tree.
524
525 If you have XML like this:
526
527 <h1>Heading</h1>
528 <p>The text...</p>
529 <h2>Next heading</h2>
530 and this QDomNode represents the <p> tag, nextSibling() will return the
531 node representing the <h2> tag.
532
533 See also previousSibling().
534
535 Example: xml/outliner/outlinetree.cpp.
536
538 Returns the name of the node.
539
540 The meaning of the name depends on the subclass: <center>.nf
541
542 </center>
543
544 See also nodeValue().
545
546 Example: xml/outliner/outlinetree.cpp.
547
549 Returns the type of the node.
550
551 See also toAttr(), toCDATASection(), toDocumentFragment(),
552 toDocument(), toDocumentType(), toElement(), toEntityReference(),
553 toText(), toEntity(), toNotation(), toProcessingInstruction(),
554 toCharacterData(), and toComment().
555
556 Reimplemented in QDomDocumentType, QDomDocument, QDomDocumentFragment,
557 QDomCharacterData, QDomAttr, QDomElement, QDomNotation, QDomEntity,
558 QDomEntityReference, and QDomProcessingInstruction.
559
561 Returns the value of the node.
562
563 The meaning of the value depends on the subclass: <center>.nf
564
565 </center>
566
567 All the other subclasses do not have a node value and will return
568 QString::null.
569
570 See also setNodeValue() and nodeName().
571
572 Example: xml/outliner/outlinetree.cpp.
573
575 Calling normalize() on an element converts all its children into a
576 standard form. This means that adjacent QDomText objects will be merged
577 into a single text object (QDomCDATASection nodes are not merged).
578
580 Returns TRUE if n and this DOM node are not equal; otherwise returns
581 FALSE.
582
584 Assigns a copy of n to this DOM node.
585
586 The data of the copy is shared (shallow copy): modifying one node will
587 also change the other. If you want to make a deep copy, use
588 cloneNode().
589
591 Returns TRUE if n and this DOM node are equal; otherwise returns FALSE.
592
594 Returns the document to which this node belongs.
595
597 Returns the parent node. If this node has no parent, a null node is
598 returned (i.e. a node for which isNull() returns TRUE).
599
601 Returns the namespace prefix of the node or QString::null if the node
602 has no namespace prefix.
603
604 Only nodes of type ElementNode or AttributeNode can have namespaces. A
605 namespace prefix must be specified at creation time. If a node was
606 created with a namespace prefix, you can change it later with
607 setPrefix().
608
609 If you create an element or attribute with
610 QDomDocument::createElement() or QDomDocument::createAttribute(), the
611 prefix will be QString::null. If you use
612 QDomDocument::createElementNS() or QDomDocument::createAttributeNS()
613 instead, the prefix will not be QString::null; but it might be an empty
614 string if the name does not have a prefix.
615
616 See also setPrefix(), localName(), namespaceURI(),
617 QDomDocument::createElementNS(), and QDomDocument::createAttributeNS().
618
620 Returns the previous sibling in the document tree. Changing the
621 returned node will also change the node in the document tree.
622
623 For example, if you have XML like this:
624
625 <h1>Heading</h1>
626 <p>The text...</p>
627 <h2>Next heading</h2>
628 and this QDomNode represents the <p> tag, previousSibling() will return
629 the node representing the <h1> tag.
630
631 See also nextSibling().
632
634 Removes oldChild from the list of children. oldChild must be a direct
635 child of this node.
636
637 Returns a new reference to oldChild on success or a null node on
638 failure.
639
640 See also insertBefore(), insertAfter(), replaceChild(), and
641 appendChild().
642
644 oldChild ) [virtual]
645 Replaces oldChild with newChild. oldChild must be a direct child of
646 this node.
647
648 If newChild is the child of another node, it is reparented to this
649 node. If newChild is a child of this node, then its position in the
650 list of children is changed.
651
652 If newChild is a QDomDocumentFragment, then oldChild is replaced by all
653 of the children of the fragment.
654
655 Returns a new reference to oldChild on success or a null node an
656 failure.
657
658 See also insertBefore(), insertAfter(), removeChild(), and
659 appendChild().
660
662 Writes the XML representation of the node and all its children to the
663 stream str. This function uses indent as the amount of space to indent
664 the node.
665
667 Sets the node's value to v.
668
669 See also nodeValue().
670
672 If the node has a namespace prefix, this function changes the namespace
673 prefix of the node to pre. Otherwise this function does nothing.
674
675 Only nodes of type ElementNode or AttributeNode can have namespaces. A
676 namespace prefix must have be specified at creation time; it is not
677 possible to add a namespace prefix afterwards.
678
679 See also prefix(), localName(), namespaceURI(),
680 QDomDocument::createElementNS(), and QDomDocument::createAttributeNS().
681
683 Converts a QDomNode into a QDomAttr. If the node is not an attribute,
684 the returned object will be null.
685
686 See also isAttr().
687
689 Converts a QDomNode into a QDomCDATASection. If the node is not a CDATA
690 section, the returned object will be null.
691
692 See also isCDATASection().
693
695 Converts a QDomNode into a QDomCharacterData. If the node is not a
696 character data node the returned object will be null.
697
698 See also isCharacterData().
699
701 Converts a QDomNode into a QDomComment. If the node is not a comment
702 the returned object will be null.
703
704 See also isComment().
705
707 Converts a QDomNode into a QDomDocument. If the node is not a document
708 the returned object will be null.
709
710 See also isDocument().
711
713 Converts a QDomNode into a QDomDocumentFragment. If the node is not a
714 document fragment the returned object will be null.
715
716 See also isDocumentFragment().
717
719 Converts a QDomNode into a QDomDocumentType. If the node is not a
720 document type the returned object will be null.
721
722 See also isDocumentType().
723
725 Converts a QDomNode into a QDomElement. If the node is not an element
726 the returned object will be null.
727
728 See also isElement().
729
730 Example: xml/outliner/outlinetree.cpp.
731
733 Converts a QDomNode into a QDomEntity. If the node is not an entity the
734 returned object will be null.
735
736 See also isEntity().
737
739 Converts a QDomNode into a QDomEntityReference. If the node is not an
740 entity reference, the returned object will be null.
741
742 See also isEntityReference().
743
745 Converts a QDomNode into a QDomNotation. If the node is not a notation
746 the returned object will be null.
747
748 See also isNotation().
749
751 Converts a QDomNode into a QDomProcessingInstruction. If the node is
752 not a processing instruction the returned object will be null.
753
754 See also isProcessingInstruction().
755
757 Converts a QDomNode into a QDomText. If the node is not a text, the
758 returned object will be null.
759
760 See also isText().
761
764 Writes the XML representation of the node node and all its children to
765 the stream str.
766
767
769 http://doc.trolltech.com/qdomnode.html
770 http://www.trolltech.com/faq/tech.html
771
773 Copyright 1992-2007 Trolltech ASA, http://www.trolltech.com. See the
774 license file included in the distribution for a complete license
775 statement.
776
778 Generated automatically from the source code.
779
781 If you find a bug in Qt, please report it as described in
782 http://doc.trolltech.com/bughowto.html. Good bug reports help us to
783 help you. Thank you.
784
785 The definitive Qt documentation is provided in HTML format; it is
786 located at $QTDIR/doc/html and can be read using Qt Assistant or with a
787 web browser. This man page is provided as a convenience for those users
788 who prefer man pages, although this format is not officially supported
789 by Trolltech.
790
791 If you find errors in this manual page, please report them to qt-
792 bugs@trolltech.com. Please include the name of the manual page
793 (qdomnode.3qt) and the Qt version (3.3.8).
794
795
796
797Trolltech AS 2 February 2007 QDomNode(3qt)