HomeHome

ClassesAnnotated - TreeFunctionsHomeStructure

QDomNode Class Reference
[ XML module ]


The QDomNode class is the base class of which the complete document tree is constructed More...

#include <qdom.h>

Inherited by QDomAttr, QDomCharacterData, QDomDocument, QDomDocumentFragment, QDomDocumentType, QDomElement, QDomEntity, QDomEntityReference, QDomNotation and QDomProcessingInstruction.

List of all member functions.

Public Members

Protected Members


Detailed Description

The QDomNode class is the base class of which the complete document tree is constructed

This class is the base class for almost all other classes in the DOM. Many methods in the DOM return a QDomNode. The various isXxx() functions can then be used to find out the kind of Node the object is. QDomNodes can be converted to derived classes by using the toXxx() functions.

To obtain the first child of the document which is an element, one can for example use:

QDomDocument d;
d.setContent( someXML );
QDomNode n = d.firstChild();
while ( !n.isNull() ) {
if ( n.isElement ) {
Element e = n.toElement();
cout << "The elements name is " << e.tagName() << endl;
}
n = n.nextSibling();
}
cout << "no element in the Document" << endl;

For further information about the Document Objct Model see http://www.w3.org/TR/REC-DOM-Level-1/ . For a more general introduction into the internals of the DOM implementation see the QDomDocument documentation.


Member Function Documentation

QDomNode::QDomNode ()

Constructs an empty Node.

QDomNode::QDomNode ( const QDomNode & n )

Copy constructor.

QDomNode::~QDomNode () [virtual]

Destructor.

QDomNode QDomNode::appendChild ( const QDomNode & newChild ) [virtual]

Appends newChild to the end of the children list.

If newChild is currently child of another parent, then it is reparented. If newChild is currently a child of this QDomNode, then its position in the list of children is changed.

Returns a new reference to newChild.

See also: insertBefore() and insertAfter().

QDomNamedNodeMap QDomNode::attributes () const [virtual]

Returns a map of all attributes. Attributes are only provided for the subclass QDomElement.

Changing the attributes in the map will also change the attributes of this QDomNode.

QDomNodeList QDomNode::childNodes () const [virtual]

Returns a list of all child nodes.

In the most often used case you will call this function on a QDomElement object. If the nodes XML looks like this:

  <body>
   <h1>Heading</h1>
   <p>Hallo <b>you</b></p>
  </body>

Then the list of child nodes of the <body> will contain the node created by the <h1> tag and the node created by the <p> tag.

The nodes in the list are not copied, so changing the nodes in the list will also change the children of this node.

See also: firstChild() and lastChild().

void QDomNode::clear ()

Dereferences the internal object. The node is then a null node.

See also: isNull().

QDomNode QDomNode::cloneNode ( bool deep = TRUE ) const [virtual]

Creates a real copy of the QDomNode.

If deep is TRUE, then the cloning is done recursive. That means all children are copied, too. Otherwise the cloned node does not contain child nodes.

QDomNode QDomNode::firstChild () const [virtual]

Returns the first child of the node. If there is no child node a null node is returned.

See also: lastChild() and childNodes().

QDomNode QDomNode::insertAfter ( const QDomNode & newChild, const QDomNode & refChild ) [virtual]

Inserts the node newChild after the child node refChild. refChild has to be a direct child of this node. If refChild is null then newChild is appended as last child.

If newChild is currently child of another parent, then it is reparented. If newChild is currently a child of this QDomNode, then its position in the list of children is changed.

If newChild is a QDomDocumentFragment, then the children of the fragment are removed from the fragment and inserted after refChild.

Returns a new reference to newChild on success or an empty node on failure.

See also: insertBefore() and replaceChild().

QDomNode QDomNode::insertBefore ( const QDomNode & newChild, const QDomNode & refChild ) [virtual]

Inserts the node newChild before the child node refChild. refChild has to be a direct child of this node. If refChild is null then newChild is inserted as first child.

If newChild is currently child of another parent, then it is reparented. If newChild is currently a child of this QDomNode, then its position in the list of children is changed.

If newChild is a QDomDocumentFragment, then the children of the fragment are removed from the fragment and inserted after refChild.

Returns a new reference to newChild on success or an empty node on failure.

See also: insertAfter() and replaceChild().

bool QDomNode::isAttr () const [virtual]

function that checks if the Node this object references is an attribute. This does not imply that this object is a QDomAttribute.

See also: toAttribute().

Reimplemented in QDomAttr.

bool QDomNode::isCDATASection () const [virtual]

function that checks if the Node this object references is a CDATASection. This does not imply that this object is a CDATASection.

See also: toCDATASection().

Reimplemented in QDomCDATASection.

bool QDomNode::isCharacterData () const [virtual]

function that checks if the Node in the DOM tree this object references is an Character data. This does not imply that this object is a QDomCharacterData.

See also: toCharacterData().

Reimplemented in QDomCharacterData.

bool QDomNode::isComment () const [virtual]

function that checks if the Node in the DOM tree this object references is a comment. This does not imply that this object is a QDomComment.

See also: toComment().

Reimplemented in QDomComment.

bool QDomNode::isDocument () const [virtual]

function that checks if the Node this object references is an document. This does not imply that this object is a QDomDocument.

See also: toDocument().

Reimplemented in QDomDocument.

bool QDomNode::isDocumentFragment () const [virtual]

function that checks if the Node this object references is a document fragment. This does not imply that this object is a QDomDocumentFragment.

See also: toDocumentFragment().

Reimplemented in QDomDocumentFragment.

bool QDomNode::isDocumentType () const [virtual]

function that checks if the Node this object references is a Document Type. This does not imply that this object is a QDomDocumentType.

See also: toDocumentType().

Reimplemented in QDomDocumentType.

bool QDomNode::isElement () const [virtual]

function that checks if the Node in the DOM tree this object references is an element. This does not imply that this object is a QDomElement.

See also: toElement().

Reimplemented in QDomElement.

bool QDomNode::isEntity () const [virtual]

function that checks if the Node in the DOM tree this object references is an entity. This does not imply that this object is a QDomEntity.

See also: toEntity().

Reimplemented in QDomEntity.

bool QDomNode::isEntityReference () const [virtual]

function that checks if the Node in the DOM tree this object references is an entity reference. This does not imply that this object is a QDomEntityReference.

See also: toEntityReference().

Reimplemented in QDomEntityReference.

bool QDomNode::isNotation () const [virtual]

function that checks if the Node in the DOM tree this object references is a notation. This does not imply that this object is a QDomNotation.

See also: toNotation().

Reimplemented in QDomNotation.

bool QDomNode::isNull () const

Returns TRUE if this node does not reference any internal object.

bool QDomNode::isProcessingInstruction () const [virtual]

function that checks if the Node in the DOM tree this object references is an processing instruction. This does not imply that this object is a QDomProcessingInstruction.

See also: toProcessingInstruction().

Reimplemented in QDomProcessingInstruction.

bool QDomNode::isText () const [virtual]

function that checks if the Node in the DOM tree this object references is a text node. This does not imply that this object is a QDomText.

See also: toText().

Reimplemented in QDomText.

QDomNode QDomNode::lastChild () const [virtual]

Returns the last child of the node. If there is no child node then a null node is returned.

See also: firstChild() and childNodes().

QDomNode QDomNode::namedItem ( const QString & name ) const

Returns the first child node which nodeName() method equals name.

If no such direct child exists, a null node is returned.

See also: nodeName().

QDomNode QDomNode::nextSibling () const [virtual]

Returns the next sibling in the document tree.

If you have XML like this:

  <h1>Heading</h1>
  <p>The text...</p>
  <h2>Next heading</h2>

and this QDomNode represents the

tag, the nextSibling will return a reference to the node representing the

tag.

See also: previousSibling().

QString QDomNode::nodeName () const [virtual]

Returns the name of the node. This name has different meanings depending on the subclass.

See also: nodeValue().

QDomNode::NodeType QDomNode::nodeType() const [virtual]

Returns the type of the node. That is used to make safe casts to one of the subclasses.

In many cases it will be more convenient to use one of the casting functions like toElement(), toText() and so on.

Reimplemented in QDomDocumentFragment, QDomElement, QDomDocumentType, QDomProcessingInstruction, QDomEntity, QDomDocument, QDomComment, QDomText, QDomCharacterData, QDomCDATASection, QDomAttr, QDomNotation and QDomEntityReference.

QString QDomNode::nodeValue () const [virtual]

Returns the nodes value. The meaning if the value depends on the subclass.

All other subclasses not listed above do not have a node value. These classes will return a null string.

See also: setNodeValue() and nodeName().

bool QDomNode::operator!= ( const QDomNode & n ) const

Returns TRUE if the nodes are not equal.

QDomNode& QDomNode::operator= ( const QDomNode & n )

Assignment operator.

bool QDomNode::operator== ( const QDomNode & n ) const

Returns TRUE if the two Nodes are equal.

QDomDocument QDomNode::ownerDocument () const [virtual]

Returns the document to which this node belongs.

QDomNode QDomNode::parentNode () const [virtual]

Returns the parent node, If this node has no parent, then a null node is returned.

QDomNode QDomNode::previousSibling () const [virtual]

Returns the previous sibling in the document tree.

If you have XML like this:

  <h1>Heading</h1>
  <p>The text...</p>
  <h2>Next heading</h2>

and this QDomNode represents the

tag, the previousSibling will return a reference to the node representing the

tag.

See also: nextSibling().

QDomNode QDomNode::removeChild ( const QDomNode & oldChild ) [virtual]

Removes oldChild from the list of children. oldChild has to be a direct child of this node.

Returns a new reference to oldChild on success or a null node on failure.

QDomNode QDomNode::replaceChild ( const QDomNode & newChild, const QDomNode & oldChild ) [virtual]

Replaces oldChild with newChild. oldChild has to be a direct child of this node.

If newChild is currently child of another parent, then it is reparented. If newChild is currently a child of this QDomNode, then its position in the list of children is changed.

If newChild is a QDomDocumentFragment, then the children of the fragment are removed from the fragment and inserted after refChild.

Returns a new reference to oldChild on success or a null node an failure.

See also: insertBefore() and insertAfter().

void QDomNode::save ( QTextStream & str, int indent ) const

Writes the XML representation of the node including all its children on the stream.

void QDomNode::setNodeValue ( const QString & v ) [virtual]

Sets the value of the node to v.

See also: nodeValue().

QDomAttr QDomNode::toAttr ()

converts a QDomNode into a QDomAttr. If the Node was not an Attribute, the returned object will be null.

See also: isAttr().

QDomCDATASection QDomNode::toCDATASection ()

converts a QDomNode into a QDomCDATASection. If the Node was not a CDATASection, the returned object will be null.

See also: isCDATASection().

QDomCharacterData QDomNode::toCharacterData ()

converts a QDomNode into a QDomCharacterData. If the Node was not a character data the returned object will be null.

See also: isCharacterData().

QDomComment QDomNode::toComment ()

converts a QDomNode into a QDomComment. If the Node was not a comment the returned object will be null.

See also: isComment().

QDomDocument QDomNode::toDocument ()

converts a QDomNode into a QDomDocument. If the Node was not a document the returned object will be null.

See also: isDocument().

QDomDocumentFragment QDomNode::toDocumentFragment ()

converts a QDomNode into a QDomDocumentFragment. If the Node was not a document fragment the returned object will be null.

See also: isDocumentFragment().

QDomDocumentType QDomNode::toDocumentType ()

converts a QDomNode into a QDomDocumentType. If the Node was not a document type the returned object will be null.

See also: isDocumentType().

QDomElement QDomNode::toElement ()

converts a QDomNode into a QDomElement. If the Node was not an element the returned object will be null.

See also: isElement().

QDomEntity QDomNode::toEntity ()

converts a QDomNode into a QDomEntity. If the Node was not an entity the returned object will be null.

See also: isEntity().

QDomEntityReference QDomNode::toEntityReference ()

converts a QDomNode into a QDomEntityReference. If the Node was not an entity reference, the returned object will be null.

See also: isEntityReference().

QDomNotation QDomNode::toNotation ()

converts a QDomNode into a QDomNotation. If the Node was not a notation the returned object will be null.

See also: isNotation().

QDomProcessingInstruction QDomNode::toProcessingInstruction ()

converts a QDomNode into a QDomProcessingInstruction. If the Node was not an processing instruction the returned object will be null.

See also: isProcessingInstruction().

QDomText QDomNode::toText ()

converts a QDomNode into a QDomText. If the Node was not a text, the returned object will be null.

See also: isText().

QDomNode::QDomNode ( QDOM_NodePrivate * n ) [protected]

For internal use only.


Search the documentation, FAQ, qt-interest archive and more (uses www.trolltech.com):


This file is part of the Qt toolkit, copyright © 1995-2000 Trolltech, all rights reserved.


Copyright İ 2000 TrolltechTrademarks
Qt version 2.2.0-beta2