Logo Search packages:      
Sourcecode: qt4-x11 version File versions  Download package

QDomNode Class Reference

Inheritance diagram for QDomNode:

QDomAttr QDomCharacterData QDomDocument QDomDocumentFragment QDomDocumentType QDomElement QDomEntity QDomEntityReference QDomNotation QDomProcessingInstruction

List of all members.

Detailed Description

The QDomNode class is the base class for all the nodes in a DOM tree.


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().

A QDomNode can be null, much like a null pointer. Creating a copy of a null node results in another null node. It is not possible to modify a null node, but it is possible to assign another, possibly non-null node to it. In this case, the copy of the null node will remain null. You can check if a QDomNode is null by calling isNull(). The empty constructor of a QDomNode (or any of the derived classes) creates a null node.

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. doc/src/snippets/code/src_xml_dom_qdom.cpp 1

For further information about the Document Object Model see {http://www.w3.org/TR/REC-DOM-Level-1/}{Level 1} and {http://www.w3.org/TR/DOM-Level-2-Core/}{Level 2 Core}. For a more general introduction of the DOM implementation see the QDomDocument documentation.

Definition at line 124 of file qdom.h.

Public Types

enum  EncodingPolicy { EncodingFromDocument = 1, EncodingFromTextStream = 2 }
enum  NodeType {
  ElementNode = 1, AttributeNode = 2, TextNode = 3, CDATASectionNode = 4,
  EntityReferenceNode = 5, EntityNode = 6, ProcessingInstructionNode = 7, CommentNode = 8,
  DocumentNode = 9, DocumentTypeNode = 10, DocumentFragmentNode = 11, NotationNode = 12,
  BaseNode = 21, CharacterDataNode = 22

Public Member Functions

QDomNode appendChild (const QDomNode &newChild)
QDomNamedNodeMap attributes () const
QDomNodeList childNodes () const
void clear ()
QDomNode cloneNode (bool deep=true) const
int columnNumber () const
QDomNode firstChild () const
QDomElement firstChildElement (const QString &tagName=QString()) const
bool hasAttributes () const
bool hasChildNodes () const
QDomNode insertAfter (const QDomNode &newChild, const QDomNode &refChild)
QDomNode insertBefore (const QDomNode &newChild, const QDomNode &refChild)
bool isAttr () const
bool isCDATASection () const
bool isCharacterData () const
bool isComment () const
bool isDocument () const
bool isDocumentFragment () const
bool isDocumentType () const
bool isElement () const
bool isEntity () const
bool isEntityReference () const
bool isNotation () const
bool isNull () const
bool isProcessingInstruction () const
bool isSupported (const QString &feature, const QString &version) const
bool isText () const
QDomNode lastChild () const
QDomElement lastChildElement (const QString &tagName=QString()) const
int lineNumber () const
QString localName () const
QDomNode namedItem (const QString &name) const
QString namespaceURI () const
QDomNode nextSibling () const
QDomElement nextSiblingElement (const QString &taName=QString()) const
QString nodeName () const
NodeType nodeType () const
QString nodeValue () const
void normalize ()
bool operator!= (const QDomNode &) const
QDomNodeoperator= (const QDomNode &)
bool operator== (const QDomNode &) const
QDomDocument ownerDocument () const
QDomNode parentNode () const
QString prefix () const
QDomNode previousSibling () const
QDomElement previousSiblingElement (const QString &tagName=QString()) const
 QDomNode (const QDomNode &)
 QDomNode ()
QDomNode removeChild (const QDomNode &oldChild)
QDomNode replaceChild (const QDomNode &newChild, const QDomNode &oldChild)
void save (QTextStream &, int, EncodingPolicy) const
void save (QTextStream &, int) const
void setNodeValue (const QString &)
void setPrefix (const QString &pre)
QDomAttr toAttr () const
QDomCDATASection toCDATASection () const
QDomCharacterData toCharacterData () const
QDomComment toComment () const
QDomDocument toDocument () const
QDomDocumentFragment toDocumentFragment () const
QDomDocumentType toDocumentType () const
QDomElement toElement () const
QDomEntity toEntity () const
QDomEntityReference toEntityReference () const
QDomNotation toNotation () const
QDomProcessingInstruction toProcessingInstruction () const
QDomText toText () const
 ~QDomNode ()

Protected Member Functions

 QDomNode (QDomNodePrivate *)

Protected Attributes

QDomNodePrivate * impl


class QDomDocument
class QDomDocumentType
class QDomNamedNodeMap
class QDomNodeList

Related Functions

(Note that these are not member functions.)

QTextStreamoperator<< (QTextStream &str, const QDomNode &node)

The documentation for this class was generated from the following files:

Generated by  Doxygen 1.6.0   Back to index