Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
QDomNode Class Reference

\reentrant More...

#include <qdom.h>

+ Inheritance diagram for QDomNode:
+ Collaboration diagram for QDomNode:

Public Types

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
}
 This enum defines the type of the node: \value ElementNode \value AttributeNode \value TextNode \value CDATASectionNode \value EntityReferenceNode \value EntityNode \value ProcessingInstructionNode \value CommentNode \value DocumentNode \value DocumentTypeNode \value DocumentFragmentNode \value NotationNode \value BaseNode A QDomNode object, i.e. More...
 
enum  EncodingPolicy { EncodingFromDocument = 1 , EncodingFromTextStream = 2 }
 

Public Member Functions

 QDomNode ()
 Constructs a \l{isNull()}{null} node.
 
 QDomNode (const QDomNode &)
 Constructs a copy of n.
 
QDomNodeoperator= (const QDomNode &)
 Assigns a copy of n to this DOM node.
 
bool operator== (const QDomNode &) const
 Returns true if n and this DOM node are equal; otherwise returns false.
 
bool operator!= (const QDomNode &) const
 Returns true if n and this DOM node are not equal; otherwise returns false.
 
 ~QDomNode ()
 Destroys the object and frees its resources.
 
QDomNode insertBefore (const QDomNode &newChild, const QDomNode &refChild)
 Inserts the node newChild before the child node refChild.
 
QDomNode insertAfter (const QDomNode &newChild, const QDomNode &refChild)
 Inserts the node newChild after the child node refChild.
 
QDomNode replaceChild (const QDomNode &newChild, const QDomNode &oldChild)
 Replaces oldChild with newChild.
 
QDomNode removeChild (const QDomNode &oldChild)
 Removes oldChild from the list of children.
 
QDomNode appendChild (const QDomNode &newChild)
 Appends newChild as the node's last child.
 
bool hasChildNodes () const
 Returns true if the node has one or more children; otherwise returns false.
 
QDomNode cloneNode (bool deep=true) const
 Creates a deep (not shallow) copy of the QDomNode.
 
void normalize ()
 Calling normalize() on an element converts all its children into a standard form.
 
bool isSupported (const QString &feature, const QString &version) const
 Returns true if the DOM implementation implements the feature feature and this feature is supported by this node in the version version; otherwise returns false.
 
QString nodeName () const
 Returns the name of the node.
 
NodeType nodeType () const
 Returns the type of the node.
 
QDomNode parentNode () const
 Returns the parent node.
 
QDomNodeList childNodes () const
 Returns a list of all direct child nodes.
 
QDomNode firstChild () const
 Returns the first child of the node.
 
QDomNode lastChild () const
 Returns the last child of the node.
 
QDomNode previousSibling () const
 Returns the previous sibling in the document tree.
 
QDomNode nextSibling () const
 Returns the next sibling in the document tree.
 
QDomNamedNodeMap attributes () const
 Returns a named node map of all attributes.
 
QDomDocument ownerDocument () const
 Returns the document to which this node belongs.
 
QString namespaceURI () const
 Returns the namespace URI of this node or an empty string if the node has no namespace URI.
 
QString localName () const
 If the node uses namespaces, this function returns the local name of the node; otherwise it returns an empty string.
 
bool hasAttributes () const
 Returns true if the node has attributes; otherwise returns false.
 
QString nodeValue () const
 Returns the value of the node.
 
void setNodeValue (const QString &)
 Sets the node's value to v.
 
QString prefix () const
 Returns the namespace prefix of the node or an empty string if the node has no namespace prefix.
 
void setPrefix (const QString &pre)
 If the node has a namespace prefix, this function changes the namespace prefix of the node to pre.
 
bool isAttr () const
 Returns true if the node is an attribute; otherwise returns false.
 
bool isCDATASection () const
 Returns true if the node is a CDATA section; otherwise returns false.
 
bool isDocumentFragment () const
 Returns true if the node is a document fragment; otherwise returns false.
 
bool isDocument () const
 Returns true if the node is a document; otherwise returns false.
 
bool isDocumentType () const
 Returns true if the node is a document type; otherwise returns false.
 
bool isElement () const
 Returns true if the node is an element; otherwise returns false.
 
bool isEntityReference () const
 Returns true if the node is an entity reference; otherwise returns false.
 
bool isText () const
 Returns true if the node is a text node; otherwise returns false.
 
bool isEntity () const
 Returns true if the node is an entity; otherwise returns false.
 
bool isNotation () const
 Returns true if the node is a notation; otherwise returns false.
 
bool isProcessingInstruction () const
 Returns true if the node is a processing instruction; otherwise returns false.
 
bool isCharacterData () const
 Returns true if the node is a character data node; otherwise returns false.
 
bool isComment () const
 Returns true if the node is a comment; otherwise returns false.
 
QDomNode namedItem (const QString &name) const
 Returns the first direct child node for which nodeName() equals name.
 
bool isNull () const
 Returns true if this node is null (i.e.
 
void clear ()
 Converts the node into a null node; if it was not a null node before, its type and contents are deleted.
 
QDomAttr toAttr () const
 Converts a QDomNode into a QDomAttr.
 
QDomCDATASection toCDATASection () const
 Converts a QDomNode into a QDomCDATASection.
 
QDomDocumentFragment toDocumentFragment () const
 Converts a QDomNode into a QDomDocumentFragment.
 
QDomDocument toDocument () const
 Converts a QDomNode into a QDomDocument.
 
QDomDocumentType toDocumentType () const
 Converts a QDomNode into a QDomDocumentType.
 
QDomElement toElement () const
 Converts a QDomNode into a QDomElement.
 
QDomEntityReference toEntityReference () const
 Converts a QDomNode into a QDomEntityReference.
 
QDomText toText () const
 Converts a QDomNode into a QDomText.
 
QDomEntity toEntity () const
 Converts a QDomNode into a QDomEntity.
 
QDomNotation toNotation () const
 Converts a QDomNode into a QDomNotation.
 
QDomProcessingInstruction toProcessingInstruction () const
 Converts a QDomNode into a QDomProcessingInstruction.
 
QDomCharacterData toCharacterData () const
 Converts a QDomNode into a QDomCharacterData.
 
QDomComment toComment () const
 Converts a QDomNode into a QDomComment.
 
void save (QTextStream &, int, EncodingPolicy=QDomNode::EncodingFromDocument) const
 Writes the XML representation of the node and all its children to the stream stream.
 
QDomElement firstChildElement (const QString &tagName=QString(), const QString &namespaceURI=QString()) const
 Returns the first child element with tag name tagName and namespace URI namespaceURI.
 
QDomElement lastChildElement (const QString &tagName=QString(), const QString &namespaceURI=QString()) const
 Returns the last child element with tag name tagName and namespace URI namespaceURI.
 
QDomElement previousSiblingElement (const QString &tagName=QString(), const QString &namespaceURI=QString()) const
 Returns the previous sibling element with tag name tagName and namespace URI namespaceURI.
 
QDomElement nextSiblingElement (const QString &taName=QString(), const QString &namespaceURI=QString()) const
 Returns the next sibling element with tag name tagName and namespace URI namespaceURI.
 
int lineNumber () const
 
int columnNumber () const
 

Protected Member Functions

 QDomNode (QDomNodePrivate *)
 

Protected Attributes

QDomNodePrivateimpl
 

Friends

class QDomDocument
 
class QDomDocumentType
 
class QDomNodeList
 
class QDomNamedNodeMap
 

Related Symbols

(Note that these are not member symbols.)

QTextStreamoperator<< (QTextStream &str, const QDomNode &node)
 Writes the XML representation of the node node and all its children to the stream str.
 

Detailed Description

\reentrant

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

\inmodule QtXml

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

\l 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.

QString someXML;
d.setContent(someXML);
QDomNode n = d.firstChild();
while (!n.isNull()) {
if (n.isElement()) {
QDomElement e = n.toElement();
cout << "Element name: " << qPrintable(e.tagName()) << '\n';
break;
}
n = n.nextSibling();
}
\reentrant
Definition qdom.h:266
\reentrant
Definition qdom.h:468
\reentrant
Definition qdom.h:87
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:127
double e
GLfloat n
#define qPrintable(string)
Definition qstring.h:1391

For further information about the Document Object Model see \l{W3C DOM Level 1}{Level 1} and \l{W3C DOM Level 2}{Level 2 Core}. For a more general introduction of the DOM implementation see the QDomDocument documentation.

Definition at line 86 of file qdom.h.

Member Enumeration Documentation

◆ EncodingPolicy

Since
4.3

This enum specifies how QDomNode::save() determines what encoding to use when serializing.

\value EncodingFromDocument The encoding is fetched from the document. \value EncodingFromTextStream The encoding is fetched from the QTextStream.

See also
QDomNode::save()
Enumerator
EncodingFromDocument 
EncodingFromTextStream 

Definition at line 106 of file qdom.h.

◆ NodeType

This enum defines the type of the node: \value ElementNode \value AttributeNode \value TextNode \value CDATASectionNode \value EntityReferenceNode \value EntityNode \value ProcessingInstructionNode \value CommentNode \value DocumentNode \value DocumentTypeNode \value DocumentFragmentNode \value NotationNode \value BaseNode A QDomNode object, i.e.

not a QDomNode subclass. \value CharacterDataNode

Enumerator
ElementNode 
AttributeNode 
TextNode 
CDATASectionNode 
EntityReferenceNode 
EntityNode 
ProcessingInstructionNode 
CommentNode 
DocumentNode 
DocumentTypeNode 
DocumentFragmentNode 
NotationNode 
BaseNode 
CharacterDataNode 

Definition at line 89 of file qdom.h.

Constructor & Destructor Documentation

◆ QDomNode() [1/3]

QDomNode::QDomNode ( )

Constructs a \l{isNull()}{null} node.

Definition at line 1471 of file qdom.cpp.

Referenced by appendChild(), cloneNode(), firstChild(), insertAfter(), insertBefore(), lastChild(), namedItem(), nextSibling(), parentNode(), previousSibling(), removeChild(), and replaceChild().

+ Here is the caller graph for this function:

◆ QDomNode() [2/3]

QDomNode::QDomNode ( const QDomNode n)

Constructs a copy of n.

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

Definition at line 1483 of file qdom.cpp.

References impl, QBasicAtomicInteger< T >::ref(), and QDomNodePrivate::ref.

+ Here is the call graph for this function:

◆ ~QDomNode()

QDomNode::~QDomNode ( )

Destroys the object and frees its resources.

Definition at line 1554 of file qdom.cpp.

References QBasicAtomicInteger< T >::deref(), impl, and QDomNodePrivate::ref.

+ Here is the call graph for this function:

◆ QDomNode() [3/3]

QDomNode::QDomNode ( QDomNodePrivate n)
protected

Constructs a new node for the data n.

Definition at line 1493 of file qdom.cpp.

References impl, QBasicAtomicInteger< T >::ref(), and QDomNodePrivate::ref.

+ Here is the call graph for this function:

Member Function Documentation

◆ appendChild()

QDomNode QDomNode::appendChild ( const QDomNode newChild)

Appends newChild as the node's last child.

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.

If newChild is a QDomElement and this node is a QDomDocument that already has an element node as a child, newChild is not added as a child and a null node is returned.

Returns a new reference to newChild on success or a \l{isNull()}{null node} on failure.

Calling this function on a null node(created, for example, with the default constructor) does nothing and returns a \l{isNull()}{null node}.

The DOM specification disallow inserting attribute nodes, but for historical reasons, QDom accepts them anyway.

See also
insertBefore(), insertAfter(), replaceChild(), removeChild()

Definition at line 2065 of file qdom.cpp.

References QDomNode(), IMPL, impl, and qWarning.

Referenced by QDomImplementation::createDocument(), DocAppend(), FileContent(), and XmlWriter::toXml().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ attributes()

QDomNamedNodeMap QDomNode::attributes ( ) const

Returns a named node map of all attributes.

Attributes are only provided for \l{QDomElement}s.

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

Definition at line 1784 of file qdom.cpp.

References attributes(), impl, QDomNodePrivate::isElement(), and QDomNamedNodeMap.

Referenced by attributes().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ childNodes()

QDomNodeList QDomNode::childNodes ( ) const

Returns a list of all direct child nodes.

Most often you will call this function on a QDomElement object.

For example, if the XML document looks like this:

<body>
<h1>Heading</h1>
<p>Hello <b>you</b></p>
</body>
GLboolean GLboolean GLboolean b
GLfloat GLfloat p
[1]

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.

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(), lastChild()

Definition at line 1700 of file qdom.cpp.

References impl, and QDomNodeList.

◆ clear()

void QDomNode::clear ( )

Converts the node into a null node; if it was not a null node before, its type and contents are deleted.

See also
isNull()

Definition at line 2100 of file qdom.cpp.

References QBasicAtomicInteger< T >::deref(), impl, and QDomNodePrivate::ref.

+ Here is the call graph for this function:

◆ cloneNode()

QDomNode QDomNode::cloneNode ( bool  deep = true) const

Creates a deep (not shallow) copy of the QDomNode.

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.

Definition at line 1810 of file qdom.cpp.

References QDomNode(), IMPL, and impl.

+ Here is the call graph for this function:

◆ columnNumber()

int QDomNode::columnNumber ( ) const
Since
4.1

For nodes created by QDomDocument::setContent(), this function returns the column number in the XML document where the node was parsed. Otherwise, -1 is returned.

See also
lineNumber(), QDomDocument::setContent()

Definition at line 2495 of file qdom.cpp.

References QDomNodePrivate::columnNumber, and impl.

◆ firstChild()

QDomNode QDomNode::firstChild ( ) const

Returns the first child of the node.

If there is no child node, a \l{isNull()}{null node} is returned. Changing the returned node will also change the node in the document tree.

See also
lastChild(), childNodes()

Definition at line 1714 of file qdom.cpp.

References QDomNode(), IMPL, and impl.

Referenced by DomText(), FileContent(), and firstChildElement().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ firstChildElement()

QDomElement QDomNode::firstChildElement ( const QString tagName = QString(),
const QString namespaceURI = QString() 
) const

Returns the first child element with tag name tagName and namespace URI namespaceURI.

If tagName is empty, returns the first child element with namespaceURI, and if namespaceURI is empty, returns the first child element with tagName. If the both parameters are empty, returns the first child element. Returns a null element if no such child exists.

See also
lastChildElement(), previousSiblingElement(), nextSiblingElement()

Definition at line 2392 of file qdom.cpp.

References child, firstChild(), QString::isEmpty(), namespaceURI(), and QDomElement::tagName().

+ Here is the call graph for this function:

◆ hasAttributes()

bool QDomNode::hasAttributes ( ) const

Returns true if the node has attributes; otherwise returns false.

See also
attributes()

Definition at line 1937 of file qdom.cpp.

References hasAttributes(), impl, and QDomNodePrivate::isElement().

Referenced by hasAttributes().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ hasChildNodes()

bool QDomNode::hasChildNodes ( ) const

Returns true if the node has one or more children; otherwise returns false.

Definition at line 2078 of file qdom.cpp.

References IMPL, and impl.

◆ insertAfter()

QDomNode QDomNode::insertAfter ( const QDomNode newChild,
const QDomNode refChild 
)

Inserts the node newChild after the child node refChild.

refChild must be a direct child of this node. If refChild is \l{isNull()}{null} then newChild is appended as this node's last child.

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 \l{isNull()}{null node} on failure.

The DOM specification disallow inserting attribute nodes, but due to historical reasons QDom accept them nevertheless.

See also
insertBefore(), replaceChild(), removeChild(), appendChild()

Definition at line 1993 of file qdom.cpp.

References QDomNode(), IMPL, and impl.

+ Here is the call graph for this function:

◆ insertBefore()

QDomNode QDomNode::insertBefore ( const QDomNode newChild,
const QDomNode refChild 
)

Inserts the node newChild before the child node refChild.

refChild must be a direct child of this node. If refChild is \l{isNull()}{null} then newChild is inserted as the node's first child.

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 \l{isNull()}{null node} on failure.

The DOM specification disallow inserting attribute nodes, but due to historical reasons QDom accept them nevertheless.

See also
insertAfter(), replaceChild(), removeChild(), appendChild()

Definition at line 1965 of file qdom.cpp.

References QDomNode(), IMPL, and impl.

+ Here is the call graph for this function:

◆ isAttr()

bool QDomNode::isAttr ( ) const

Returns true if the node is an attribute; otherwise returns false.

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

Definition at line 2181 of file qdom.cpp.

References impl, and QDomNodePrivate::isAttr().

Referenced by setPrefix().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isCDATASection()

bool QDomNode::isCDATASection ( ) const

Returns true if the node is a CDATA section; otherwise returns false.

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

Definition at line 2198 of file qdom.cpp.

References impl, and QDomNodePrivate::isCDATASection().

+ Here is the call graph for this function:

◆ isCharacterData()

bool QDomNode::isCharacterData ( ) const

Returns true if the node is a character data node; otherwise returns false.

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

Definition at line 2358 of file qdom.cpp.

References impl, and QDomNodePrivate::isCharacterData().

+ Here is the call graph for this function:

◆ isComment()

bool QDomNode::isComment ( ) const

Returns true if the node is a comment; otherwise returns false.

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

Definition at line 2373 of file qdom.cpp.

References impl, and QDomNodePrivate::isComment().

+ Here is the call graph for this function:

◆ isDocument()

bool QDomNode::isDocument ( ) const

Returns true if the node is a document; otherwise returns false.

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

Definition at line 2230 of file qdom.cpp.

References impl, and QDomNodePrivate::isDocument().

Referenced by save().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isDocumentFragment()

bool QDomNode::isDocumentFragment ( ) const

Returns true if the node is a document fragment; otherwise returns false.

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

Definition at line 2215 of file qdom.cpp.

References impl, and QDomNodePrivate::isDocumentFragment().

+ Here is the call graph for this function:

◆ isDocumentType()

bool QDomNode::isDocumentType ( ) const

Returns true if the node is a document type; otherwise returns false.

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

Definition at line 2247 of file qdom.cpp.

References impl, and QDomNodePrivate::isDocumentType().

+ Here is the call graph for this function:

◆ isElement()

bool QDomNode::isElement ( ) const

Returns true if the node is an element; otherwise returns false.

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

Definition at line 2262 of file qdom.cpp.

References impl, and QDomNodePrivate::isElement().

Referenced by setPrefix().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isEntity()

bool QDomNode::isEntity ( ) const

Returns true if the node is an entity; otherwise returns false.

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

Definition at line 2309 of file qdom.cpp.

References impl, and QDomNodePrivate::isEntity().

+ Here is the call graph for this function:

◆ isEntityReference()

bool QDomNode::isEntityReference ( ) const

Returns true if the node is an entity reference; otherwise returns false.

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

Definition at line 2279 of file qdom.cpp.

References impl, and QDomNodePrivate::isEntityReference().

+ Here is the call graph for this function:

◆ isNotation()

bool QDomNode::isNotation ( ) const

Returns true if the node is a notation; otherwise returns false.

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

Definition at line 2324 of file qdom.cpp.

References impl, and QDomNodePrivate::isNotation().

+ Here is the call graph for this function:

◆ isNull()

bool QDomNode::isNull ( ) const

Returns true if this node is null (i.e.

if it has no type or contents); otherwise returns false.

Definition at line 2089 of file qdom.cpp.

References impl.

Referenced by QDomImplementation::createDocument(), QDomDocument::importNode(), nextSiblingElement(), previousSiblingElement(), and removeChild().

+ Here is the caller graph for this function:

◆ isProcessingInstruction()

bool QDomNode::isProcessingInstruction ( ) const

Returns true if the node is a processing instruction; otherwise returns false.

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

Definition at line 2341 of file qdom.cpp.

References impl, and QDomNodePrivate::isProcessingInstruction().

+ Here is the call graph for this function:

◆ isSupported()

bool QDomNode::isSupported ( const QString feature,
const QString version 
) const

Returns true if the DOM implementation implements the feature feature and this feature is supported by this node in the version version; otherwise returns false.

See also
QDomImplementation::hasFeature()

Definition at line 1837 of file qdom.cpp.

References i.

◆ isText()

bool QDomNode::isText ( ) const

Returns true if the node is a text node; otherwise returns false.

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

Definition at line 2294 of file qdom.cpp.

References impl, and QDomNodePrivate::isText().

+ Here is the call graph for this function:

◆ lastChild()

QDomNode QDomNode::lastChild ( ) const

Returns the last child of the node.

If there is no child node, a \l{isNull()}{null node} is returned. Changing the returned node will also change the node in the document tree.

See also
firstChild(), childNodes()

Definition at line 1728 of file qdom.cpp.

References QDomNode(), IMPL, and impl.

Referenced by lastChildElement().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ lastChildElement()

QDomElement QDomNode::lastChildElement ( const QString tagName = QString(),
const QString namespaceURI = QString() 
) const

Returns the last child element with tag name tagName and namespace URI namespaceURI.

If tagName is empty, returns the last child element with namespaceURI, and if namespaceURI is empty, returns the last child element with tagName. If the both parameters are empty, returns the last child element. Returns a null element if no such child exists.

See also
firstChildElement(), previousSiblingElement(), nextSiblingElement()

Definition at line 2414 of file qdom.cpp.

References child, QString::isEmpty(), lastChild(), namespaceURI(), and QDomElement::tagName().

+ Here is the call graph for this function:

◆ lineNumber()

int QDomNode::lineNumber ( ) const
Since
4.1

For nodes created by QDomDocument::setContent(), this function returns the line number in the XML document where the node was parsed. Otherwise, -1 is returned.

See also
columnNumber(), QDomDocument::setContent()

Definition at line 2481 of file qdom.cpp.

References impl, and QDomNodePrivate::lineNumber.

◆ localName()

QString QDomNode::localName ( ) const

If the node uses namespaces, this function returns the local name of the node; otherwise it returns an empty string.

Only nodes of type \l{QDomNode::NodeType}{ElementNode} or \l{QDomNode::NodeType}{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(), QDomDocument::createAttributeNS()

Definition at line 1925 of file qdom.cpp.

References IMPL, and impl.

Referenced by QDomElement::attributeNodeNS(), QDomElement::attributeNS(), QDomDocument::elementsByTagNameNS(), QDomElement::elementsByTagNameNS(), QDomElement::hasAttributeNS(), and QDomElement::removeAttributeNS().

+ Here is the caller graph for this function:

◆ namedItem()

QDomNode QDomNode::namedItem ( const QString name) const

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

Shortcut to avoid dealing with QDomNodeList all the time.

If no such direct child exists, a \l{isNull()}{null node} is returned.

See also
nodeName()

Definition at line 2116 of file qdom.cpp.

References QDomNode(), impl, and QDomNodePrivate::namedItem().

+ Here is the call graph for this function:

◆ namespaceURI()

QString QDomNode::namespaceURI ( ) const

Returns the namespace URI of this node or an empty string if the node has no namespace URI.

Only nodes of type \l{QDomNode::NodeType}{ElementNode} or \l{QDomNode::NodeType}{AttributeNode} can have namespaces. A namespace URI must be specified at creation time and cannot be changed later.

See also
prefix(), localName(), QDomDocument::createElementNS(), QDomDocument::createAttributeNS()

Definition at line 1855 of file qdom.cpp.

References IMPL, and impl.

Referenced by firstChildElement(), lastChildElement(), nextSiblingElement(), and previousSiblingElement().

+ Here is the caller graph for this function:

◆ nextSibling()

QDomNode QDomNode::nextSibling ( ) const

Returns the next sibling in the document tree.

Changing the returned node will also change the node in the document tree.

If you have XML like this:

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

and this QDomNode represents the

tag, nextSibling() will return the node representing the

tag. \sa previousSibling()

Definition at line 1768 of file qdom.cpp.

References QDomNode(), IMPL, and impl.

Referenced by nextSiblingElement().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ nextSiblingElement()

QDomElement QDomNode::nextSiblingElement ( const QString tagName = QString(),
const QString namespaceURI = QString() 
) const

Returns the next sibling element with tag name tagName and namespace URI namespaceURI.

If tagName is empty, returns the next sibling element with namespaceURI, and if namespaceURI is empty, returns the next sibling child element with tagName. If the both parameters are empty, returns the next sibling element. Returns a null element if no such sibling exists.

See also
firstChildElement(), previousSiblingElement(), lastChildElement()

Definition at line 2437 of file qdom.cpp.

References QString::isEmpty(), isNull(), namespaceURI(), nextSibling(), QDomElement::tagName(), and toElement().

+ Here is the call graph for this function:

◆ nodeName()

QString QDomNode::nodeName ( ) const

Returns the name of the node.

The meaning of the name depends on the subclass:

\table \header

{Note:} This function does not take the presence of namespaces into account when processing the names of element and attribute nodes. As a result, the returned name can contain any namespace prefix that may be present. To obtain the node name of an element or attribute, use localName(); to obtain the namespace prefix, use namespaceURI().

See also
nodeValue()

Definition at line 1589 of file qdom.cpp.

References IMPL, and impl.

◆ nodeType()

QDomNode::NodeType QDomNode::nodeType ( ) const

Returns the type of the node.

See also
toAttr(), toCDATASection(), toDocumentFragment(), toDocument(), toDocumentType(), toElement(), toEntityReference(), toText(), toEntity(), toNotation(), toProcessingInstruction(), toCharacterData(), toComment()

Definition at line 1664 of file qdom.cpp.

References BaseNode, IMPL, and impl.

Referenced by QDomCharacterData::nodeType().

+ Here is the caller graph for this function:

◆ nodeValue()

QString QDomNode::nodeValue ( ) const

Returns the value of the node.

The meaning of the value depends on the subclass: \table \header

All the other subclasses do not have a node value and will return an empty string.

See also
setNodeValue(), nodeName()

Definition at line 1617 of file qdom.cpp.

References IMPL, and impl.

◆ normalize()

void QDomNode::normalize ( )

Calling normalize() on an element converts all its children into a standard form.

This means that adjacent QDomText objects will be merged into a single text object (QDomCDATASection nodes are not merged).

Definition at line 1823 of file qdom.cpp.

References IMPL, and impl.

◆ operator!=()

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

Returns true if n and this DOM node are not equal; otherwise returns false.

Definition at line 1546 of file qdom.cpp.

References impl.

◆ operator=()

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

Assigns a copy of n to this DOM node.

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

Definition at line 1507 of file qdom.cpp.

References QBasicAtomicInteger< T >::deref(), impl, QBasicAtomicInteger< T >::ref(), and QDomNodePrivate::ref.

+ Here is the call graph for this function:

◆ operator==()

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

Returns true if n and this DOM node are equal; otherwise returns false.

Any instance of QDomNode acts as a reference to an underlying data structure in QDomDocument. The test for equality checks if the two references point to the same underlying node. For example:

QDomDocument document;
QDomElement element1 = document.documentElement();
QDomElement element2 = element1;

The two nodes (QDomElement is a QDomNode subclass) both refer to the document's root element, and {element1 == element2} will return true. On the other hand:

QDomElement element3 = document.createElement("MyElement");
QDomElement element4 = document.createElement("MyElement");

Even though both nodes are empty elements carrying the same name, {element3 == element4} will return false because they refer to two different nodes in the underlying data structure.

Definition at line 1537 of file qdom.cpp.

References impl.

◆ ownerDocument()

QDomDocument QDomNode::ownerDocument ( ) const

Returns the document to which this node belongs.

Definition at line 1795 of file qdom.cpp.

References IMPL, impl, and QDomDocument.

◆ parentNode()

QDomNode QDomNode::parentNode ( ) const

Returns the parent node.

If this node has no parent, a null node is returned (i.e. a node for which isNull() returns true).

Definition at line 1675 of file qdom.cpp.

References QDomNode(), IMPL, and impl.

+ Here is the call graph for this function:

◆ prefix()

QString QDomNode::prefix ( ) const

Returns the namespace prefix of the node or an empty string if the node has no namespace prefix.

Only nodes of type \l{QDomNode::NodeType}{ElementNode} or \l{QDomNode::NodeType}{AttributeNode} can have namespaces. A namespace prefix must be specified at creation time. If a node was created with a namespace prefix, you can change it later with setPrefix().

If you create an element or attribute with QDomDocument::createElement() or QDomDocument::createAttribute(), the prefix will be an empty string. If you use QDomDocument::createElementNS() or QDomDocument::createAttributeNS() instead, the prefix will not be an empty string; but it might be an empty string if the name does not have a prefix.

See also
setPrefix(), localName(), namespaceURI(), QDomDocument::createElementNS(), QDomDocument::createAttributeNS()

Definition at line 1884 of file qdom.cpp.

References IMPL, and impl.

◆ previousSibling()

QDomNode QDomNode::previousSibling ( ) const

Returns the previous sibling in the document tree.

Changing the returned node will also change the node in the document tree.

For example, if you have XML like this:

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

and this QDomNode represents the <p> tag, previousSibling() will return the node representing the <h1> tag.

See also
nextSibling()

Definition at line 1748 of file qdom.cpp.

References QDomNode(), IMPL, and impl.

Referenced by previousSiblingElement().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ previousSiblingElement()

QDomElement QDomNode::previousSiblingElement ( const QString tagName = QString(),
const QString namespaceURI = QString() 
) const

Returns the previous sibling element with tag name tagName and namespace URI namespaceURI.

If tagName is empty, returns the previous sibling element with namespaceURI, and if namespaceURI is empty, returns the previous sibling element with tagName. If the both parameters are empty, returns the previous sibling element. Returns a null element if no such sibling exists.

See also
firstChildElement(), nextSiblingElement(), lastChildElement()

Definition at line 2460 of file qdom.cpp.

References QString::isEmpty(), isNull(), namespaceURI(), previousSibling(), QDomElement::tagName(), and toElement().

+ Here is the call graph for this function:

◆ removeChild()

QDomNode QDomNode::removeChild ( const QDomNode oldChild)

Removes oldChild from the list of children.

oldChild must be a direct child of this node.

Returns a new reference to oldChild on success or a \l{isNull()}{null node} on failure.

See also
insertBefore(), insertAfter(), replaceChild(), appendChild()

Definition at line 2030 of file qdom.cpp.

References QDomNode(), IMPL, impl, and isNull().

+ Here is the call graph for this function:

◆ replaceChild()

QDomNode QDomNode::replaceChild ( const QDomNode newChild,
const QDomNode oldChild 
)

Replaces oldChild with newChild.

oldChild must be a direct child of this node.

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 oldChild is replaced by all of the children of the fragment.

Returns a new reference to oldChild on success or a \l{isNull()}{null node} on failure.

See also
insertBefore(), insertAfter(), removeChild(), appendChild()

Definition at line 2015 of file qdom.cpp.

References QDomNode(), IMPL, and impl.

+ Here is the call graph for this function:

◆ save()

void QDomNode::save ( QTextStream stream,
int  indent,
EncodingPolicy  encodingPolicy = QDomNode::EncodingFromDocument 
) const

Writes the XML representation of the node and all its children to the stream stream.

This function uses indent as the amount of space to indent the node.

If the document contains invalid XML characters or characters that cannot be encoded in the given encoding, the result and behavior is undefined.

If encodingPolicy is QDomNode::EncodingFromDocument and this node is a document node, the encoding of text stream stream's encoding is set by treating a processing instruction by name "xml" as an XML declaration, if one exists, and otherwise defaults to UTF-8. XML declarations are not processing instructions, but this behavior exists for historical reasons. If this node is not a document node, the text stream's encoding is used.

If encodingPolicy is EncodingFromTextStream and this node is a document node, this function behaves as save(QTextStream &str, int indent) with the exception that the encoding specified in the text stream stream is used.

If the document contains invalid XML characters or characters that cannot be encoded in the given encoding, the result and behavior is undefined.

Since
4.2

Definition at line 2148 of file qdom.cpp.

References IMPL, impl, and isDocument().

Referenced by operator<<(), and QDomDocument::toString().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setNodeValue()

void QDomNode::setNodeValue ( const QString v)

Sets the node's value to v.

See also
nodeValue()

Definition at line 1629 of file qdom.cpp.

References IMPL, and impl.

◆ setPrefix()

void QDomNode::setPrefix ( const QString pre)

If the node has a namespace prefix, this function changes the namespace prefix of the node to pre.

Otherwise this function does nothing.

Only nodes of type \l{QDomNode::NodeType}{ElementNode} or \l{QDomNode::NodeType}{AttributeNode} can have namespaces. A namespace prefix must have be specified at creation time; it is not possible to add a namespace prefix afterwards.

See also
prefix(), localName(), namespaceURI(), QDomDocument::createElementNS(), QDomDocument::createAttributeNS()

Definition at line 1905 of file qdom.cpp.

References IMPL, impl, isAttr(), and isElement().

+ Here is the call graph for this function:

◆ toAttr()

QDomAttr QDomNode::toAttr ( ) const

Converts a QDomNode into a QDomAttr.

If the node is not an attribute, the returned object will be \l{QDomNode::isNull()}{null}.

See also
isAttr()

Definition at line 6803 of file qdom.cpp.

References impl, and QDomNodePrivate::isAttr().

+ Here is the call graph for this function:

◆ toCDATASection()

QDomCDATASection QDomNode::toCDATASection ( ) const

Converts a QDomNode into a QDomCDATASection.

If the node is not a CDATA section, the returned object will be \l{QDomNode::isNull()}{null}.

See also
isCDATASection()

Definition at line 6816 of file qdom.cpp.

References impl, and QDomNodePrivate::isCDATASection().

+ Here is the call graph for this function:

◆ toCharacterData()

QDomCharacterData QDomNode::toCharacterData ( ) const

Converts a QDomNode into a QDomCharacterData.

If the node is not a character data node the returned object will be \l{QDomNode::isNull()}{null}.

See also
isCharacterData()

Definition at line 6946 of file qdom.cpp.

References impl, and QDomNodePrivate::isCharacterData().

+ Here is the call graph for this function:

◆ toComment()

QDomComment QDomNode::toComment ( ) const

Converts a QDomNode into a QDomComment.

If the node is not a comment the returned object will be \l{QDomNode::isNull()}{null}.

See also
isComment()

Definition at line 6959 of file qdom.cpp.

References impl, and QDomNodePrivate::isComment().

+ Here is the call graph for this function:

◆ toDocument()

QDomDocument QDomNode::toDocument ( ) const

Converts a QDomNode into a QDomDocument.

If the node is not a document the returned object will be \l{QDomNode::isNull()}{null}.

See also
isDocument()

Definition at line 6842 of file qdom.cpp.

References impl, QDomNodePrivate::isDocument(), and QDomDocument.

+ Here is the call graph for this function:

◆ toDocumentFragment()

QDomDocumentFragment QDomNode::toDocumentFragment ( ) const

Converts a QDomNode into a QDomDocumentFragment.

If the node is not a document fragment the returned object will be \l{QDomNode::isNull()}{null}.

See also
isDocumentFragment()

Definition at line 6829 of file qdom.cpp.

References impl, and QDomNodePrivate::isDocumentFragment().

+ Here is the call graph for this function:

◆ toDocumentType()

QDomDocumentType QDomNode::toDocumentType ( ) const

Converts a QDomNode into a QDomDocumentType.

If the node is not a document type the returned object will be \l{QDomNode::isNull()}{null}.

See also
isDocumentType()

Definition at line 6855 of file qdom.cpp.

References impl, QDomNodePrivate::isDocumentType(), and QDomDocumentType.

+ Here is the call graph for this function:

◆ toElement()

QDomElement QDomNode::toElement ( ) const

Converts a QDomNode into a QDomElement.

If the node is not an element the returned object will be \l{QDomNode::isNull()}{null}.

See also
isElement()

Definition at line 6868 of file qdom.cpp.

References impl, and QDomNodePrivate::isElement().

Referenced by nextSiblingElement(), and previousSiblingElement().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ toEntity()

QDomEntity QDomNode::toEntity ( ) const

Converts a QDomNode into a QDomEntity.

If the node is not an entity the returned object will be \l{QDomNode::isNull()}{null}.

See also
isEntity()

Definition at line 6907 of file qdom.cpp.

References impl, and QDomNodePrivate::isEntity().

+ Here is the call graph for this function:

◆ toEntityReference()

QDomEntityReference QDomNode::toEntityReference ( ) const

Converts a QDomNode into a QDomEntityReference.

If the node is not an entity reference, the returned object will be \l{QDomNode::isNull()}{null}.

See also
isEntityReference()

Definition at line 6881 of file qdom.cpp.

References impl, and QDomNodePrivate::isEntityReference().

+ Here is the call graph for this function:

◆ toNotation()

QDomNotation QDomNode::toNotation ( ) const

Converts a QDomNode into a QDomNotation.

If the node is not a notation the returned object will be \l{QDomNode::isNull()}{null}.

See also
isNotation()

Definition at line 6920 of file qdom.cpp.

References impl, and QDomNodePrivate::isNotation().

+ Here is the call graph for this function:

◆ toProcessingInstruction()

QDomProcessingInstruction QDomNode::toProcessingInstruction ( ) const

Converts a QDomNode into a QDomProcessingInstruction.

If the node is not a processing instruction the returned object will be \l{QDomNode::isNull()}{null}.

See also
isProcessingInstruction()

Definition at line 6933 of file qdom.cpp.

References impl, and QDomNodePrivate::isProcessingInstruction().

+ Here is the call graph for this function:

◆ toText()

QDomText QDomNode::toText ( ) const

Converts a QDomNode into a QDomText.

If the node is not a text, the returned object will be \l{QDomNode::isNull()}{null}.

See also
isText()

Definition at line 6894 of file qdom.cpp.

References impl, and QDomNodePrivate::isText().

Referenced by DomText().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Friends And Related Symbol Documentation

◆ operator<<()

QTextStream & operator<< ( QTextStream str,
const QDomNode node 
)
related

Writes the XML representation of the node node and all its children to the stream str.

Definition at line 2165 of file qdom.cpp.

References save(), and str.

+ Here is the call graph for this function:

◆ QDomDocument

friend class QDomDocument
friend

Definition at line 204 of file qdom.h.

Referenced by ownerDocument(), and toDocument().

◆ QDomDocumentType

friend class QDomDocumentType
friend

Definition at line 205 of file qdom.h.

Referenced by QDomDocument::doctype(), and toDocumentType().

◆ QDomNamedNodeMap

◆ QDomNodeList

Member Data Documentation

◆ impl

QDomNodePrivate* QDomNode::impl
protected

Definition at line 200 of file qdom.h.

Referenced by QDomDocument::QDomDocument(), QDomDocument::QDomDocument(), QDomDocument::QDomDocument(), QDomNode(), QDomNode(), ~QDomNode(), appendChild(), QDomCharacterData::appendData(), QDomElement::attribute(), QDomElement::attributeNode(), QDomElement::attributeNodeNS(), QDomElement::attributeNS(), attributes(), QDomElement::attributes(), childNodes(), clear(), cloneNode(), columnNumber(), QDomDocument::createAttribute(), QDomDocument::createAttributeNS(), QDomDocument::createCDATASection(), QDomDocument::createComment(), QDomDocument::createDocumentFragment(), QDomDocument::createElement(), QDomDocument::createElementNS(), QDomDocument::createEntityReference(), QDomDocument::createProcessingInstruction(), QDomDocument::createTextNode(), QDomCharacterData::data(), QDomProcessingInstruction::data(), QDomCharacterData::deleteData(), QDomDocument::doctype(), QDomDocument::documentElement(), QDomDocument::elementsByTagName(), QDomElement::elementsByTagName(), QDomDocument::elementsByTagNameNS(), QDomElement::elementsByTagNameNS(), QDomDocumentType::entities(), firstChild(), QDomElement::hasAttribute(), QDomElement::hasAttributeNS(), hasAttributes(), hasChildNodes(), QDomDocument::implementation(), QDomDocument::importNode(), insertAfter(), insertBefore(), QDomCharacterData::insertData(), QDomDocumentType::internalSubset(), isAttr(), isCDATASection(), isCharacterData(), isComment(), isDocument(), isDocumentFragment(), isDocumentType(), isElement(), isEntity(), isEntityReference(), isNotation(), isNull(), isProcessingInstruction(), isText(), lastChild(), QDomCharacterData::length(), lineNumber(), localName(), QDomDocumentType::name(), QDomAttr::name(), namedItem(), namespaceURI(), nextSibling(), nodeName(), nodeType(), QDomCharacterData::nodeType(), nodeValue(), normalize(), QDomEntity::notationName(), QDomDocumentType::notations(), operator!=(), operator=(), operator==(), ownerDocument(), QDomAttr::ownerElement(), parentNode(), prefix(), previousSibling(), QDomDocumentType::publicId(), QDomNotation::publicId(), QDomEntity::publicId(), QDomElement::removeAttribute(), QDomElement::removeAttributeNode(), QDomElement::removeAttributeNS(), removeChild(), replaceChild(), QDomCharacterData::replaceData(), save(), QDomElement::setAttribute(), QDomElement::setAttribute(), QDomElement::setAttribute(), QDomElement::setAttribute(), QDomElement::setAttribute(), QDomElement::setAttributeNode(), QDomElement::setAttributeNodeNS(), QDomElement::setAttributeNS(), QDomElement::setAttributeNS(), QDomElement::setAttributeNS(), QDomElement::setAttributeNS(), QDomDocument::setContent(), QDomCharacterData::setData(), QDomProcessingInstruction::setData(), QDomNamedNodeMap::setNamedItem(), QDomNamedNodeMap::setNamedItemNS(), setNodeValue(), setPrefix(), QDomElement::setTagName(), QDomAttr::setValue(), QDomAttr::specified(), QDomText::splitText(), QDomCharacterData::substringData(), QDomDocumentType::systemId(), QDomNotation::systemId(), QDomEntity::systemId(), QDomElement::tagName(), QDomProcessingInstruction::target(), QDomElement::text(), toAttr(), toCDATASection(), toCharacterData(), toComment(), toDocument(), toDocumentFragment(), toDocumentType(), toElement(), toEntity(), toEntityReference(), toNotation(), toProcessingInstruction(), toText(), and QDomAttr::value().


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