#include <qdom.h>
Inherited by QDomDocumentType, QDomDocument, QDomDocumentFragment, QDomCharacterData, QDomAttr, QDomElement, QDomNotation, QDomEntity, QDomEntityReference, and QDomProcessingInstruction.
Many functions in the DOM return a QDomNode.
You can find out the type of a node using isAttr(), isCDATASection(), isDocumentFragment(), isDocument(), isDocumentType(), isElement(), isEntityReference(), isText(), isEntity(), isNotation(), isProcessingInstruction(), isCharacterData() and isComment().
A QDomNode can be converted into one of its subclasses using toAttr(), toCDATASection(), toDocumentFragment(), toDocument(), toDocumentType(), toElement(), toEntityReference(), toText(), toEntity(), toNotation(), toProcessingInstruction(), toCharacterData() or toComment(). You can convert a node to a null node with clear().
Copies of the QDomNode class share their data using explicit sharing. This means that modifying one node will change all copies. This is especially useful in combination with functions which return a QDomNode, e.g. firstChild(). You can make an independent (deep) copy of the node with cloneNode().
Nodes are inserted with insertBefore(), insertAfter() or appendChild(). You can replace one node with another using replaceChild() and remove a node with removeChild().
To traverse nodes use firstChild() to get a node's first child (if any), and nextSibling() to traverse. QDomNode also provides lastChild(), previousSibling() and parentNode(). To find the first child node with a particular node name use namedItem().
To find out if a node has children use hasChildNodes() and to get a list of all of a node's children use childNodes().
The node's name and value (the meaning of which varies depending on its type) is returned by nodeName() and nodeValue() respectively. The node's type is returned by nodeType(). The node's value can be set with setNodeValue().
The document to which the node belongs is returned by ownerDocument().
Adjacent QDomText nodes can be merged into a single node with normalize().
QDomElement nodes have attributes which can be retrieved with attributes().
QDomElement and QDomAttr nodes can have namespaces which can be retrieved with namespaceURI(). Their local name is retrieved with localName(), and their prefix with prefix(). The prefix can be set with setPrefix().
You can write the XML representation of the node to a text stream with save().
The following example looks for the first element in an XML document and prints the names of all the elements that are its direct children.
QDomDocument d;
d.setContent( someXML );
QDomNode n = d.firstChild();
while ( !n.isNull() ) {
if ( n.isElement() ) {
QDomElement e = n.toElement();
cout << "Element name: " << e.tagName() << endl;
break;
}
n = n.nextSibling();
}
For further information about the Document Object Model see http://www.w3.org/TR/REC-DOM-Level-1/ and http://www.w3.org/TR/DOM-Level-2-Core/. For a more general introduction of the DOM implementation see the QDomDocument documentation.
The data of the copy is shared (shallow copy): modifying one node will also change the other. If you want to make a deep copy, use cloneNode().
If newChild is the child of another node, it is reparented to this node. If newChild is a child of this node, 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 appended.
Returns a new reference to newChild.
See also insertBefore(), insertAfter(), replaceChild(), and removeChild().
Changing the attributes in the map will also change the attributes of this QDomNode.
Most often you will call this function on a QDomElement object.
For example, if the XML document looks like this:
Then the list of child nodes for the "body"-element will contain the node created by the <h1> tag and the node created by the <p> tag.
<body>
<h1>Heading</h1>
<p>Hello <b>you</b></p>
</body>
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().
If deep is TRUE, then the cloning is done recursively which means that all the node's children are deep copied too. If deep is FALSE only the node itself is copied and the copy will have no child nodes.
See also lastChild() and childNodes().
Example: xml/outliner/outlinetree.cpp.
If newChild is the child of another node, it is reparented to this node. If newChild is a child of this node, 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 a null node on failure.
See also insertBefore(), replaceChild(), removeChild(), and appendChild().
If newChild is the child of another node, it is reparented to this node. If newChild is a child of this node, 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 before refChild.
Returns a new reference to newChild on success or a null node on failure.
See also insertAfter(), replaceChild(), removeChild(), and appendChild().
If this function returns TRUE, it does not imply that this object is a QDomAttribute; you can get the QDomAttribute with toAttribute().
See also toAttr().
If this function returns TRUE, it does not imply that this object is a QDomCDATASection; you can get the QDomCDATASection with toCDATASection().
See also toCDATASection().
Reimplemented in QDomCDATASection.
If this function returns TRUE, it does not imply that this object is a QDomCharacterData; you can get the QDomCharacterData with toCharacterData().
See also toCharacterData().
Reimplemented in QDomCharacterData.
If this function returns TRUE, it does not imply that this object is a QDomComment; you can get the QDomComment with toComment().
See also toComment().
If this function returns TRUE, it does not imply that this object is a QDomDocument; you can get the QDomDocument with toDocument().
See also toDocument().
Reimplemented in QDomDocument.
If this function returns TRUE, it does not imply that this object is a QDomDocumentFragment; you can get the QDomDocumentFragment with toDocumentFragment().
See also toDocumentFragment().
Reimplemented in QDomDocumentFragment.
If this function returns TRUE, it does not imply that this object is a QDomDocumentType; you can get the QDomDocumentType with toDocumentType().
See also toDocumentType().
Reimplemented in QDomDocumentType.
If this function returns TRUE, it does not imply that this object is a QDomElement; you can get the QDomElement with toElement().
See also toElement().
Example: xml/outliner/outlinetree.cpp.
If this function returns TRUE, it does not imply that this object is a QDomEntity; you can get the QDomEntity with toEntity().
See also toEntity().
If this function returns TRUE, it does not imply that this object is a QDomEntityReference; you can get the QDomEntityReference with toEntityReference().
See also toEntityReference().
Reimplemented in QDomEntityReference.
If this function returns TRUE, it does not imply that this object is a QDomNotation; you can get the QDomNotation with toNotation().
See also toNotation().
Reimplemented in QDomNotation.
Example: xml/outliner/outlinetree.cpp.
If this function returns TRUE, it does not imply that this object is a QDomProcessingInstruction; you can get the QProcessingInstruction with toProcessingInstruction().
See also toProcessingInstruction().
Reimplemented in QDomProcessingInstruction.
See also QDomImplementation::hasFeature().
If this function returns TRUE, it does not imply that this object is a QDomText; you can get the QDomText with toText().
See also toText().
See also firstChild() and childNodes().
Only nodes of type ElementNode or AttributeNode can have namespaces. A namespace must have been specified at creation time; it is not possible to add a namespace afterwards.
See also prefix(), namespaceURI(), QDomDocument::createElementNS(), and QDomDocument::createAttributeNS().