Qt 4.8
Public Types | Public Functions | Protected Functions | Protected Variables | Friends | Related Functions | List of all members
QDomNode Class Reference

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

#include <qdom.h>

Inheritance diagram for QDomNode:
QDomAttr QDomCharacterData QDomDocument QDomDocumentFragment QDomDocumentType QDomElement QDomEntity QDomEntityReference QDomNotation QDomProcessingInstruction

Public Types

enum  EncodingPolicy { EncodingFromDocument = 1, EncodingFromTextStream = 2 }
 This enum specifies how QDomNode::save() determines what encoding to use when serializing. More...
 
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: More...
 

Public Functions

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

Protected Functions

 QDomNode (QDomNodePrivate *)
 Constructs a new node for the data n. More...
 

Protected Variables

QDomNodePrivateimpl
 

Friends

class QDomDocument
 
class QDomDocumentType
 
class QDomNamedNodeMap
 
class QDomNodeList
 

Related Functions

(Note that these are not member functions.)

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

Detailed Description

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

Note
This class or function is reentrant.
Attention
Module: 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 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.

d.setContent(someXML);
while (!n.isNull()) {
if (n.isElement()) {
cout << "Element name: " << e.tagName() << endl;
break;
}
n = n.nextSibling();
}

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

Definition at line 128 of file qdom.h.

Enumerations

◆ EncodingPolicy

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

Since
4.3
  • EncodingFromDocument The encoding is fetched from the document.
  • EncodingFromTextStream The encoding is fetched from the QTextStream.

See also the overload of the save() function that takes an EncodingPolicy.

Enumerator
EncodingFromDocument 
EncodingFromTextStream 

Definition at line 148 of file qdom.h.

◆ NodeType

This enum defines the type of the node:

  • ElementNode
  • AttributeNode
  • TextNode
  • CDATASectionNode
  • EntityReferenceNode
  • EntityNode
  • ProcessingInstructionNode
  • CommentNode
  • DocumentNode
  • DocumentTypeNode
  • DocumentFragmentNode
  • NotationNode
  • BaseNode A QDomNode object, i.

e. not a QDomNode subclass.

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

Definition at line 131 of file qdom.h.

Constructors and Destructors

◆ QDomNode() [1/3]

QDomNode::QDomNode ( )

Constructs a null node.

Definition at line 2057 of file qdom.cpp.

Referenced by QDomDocument::importNode().

2058 {
2059  impl = 0;
2060 }
QDomNodePrivate * impl
Definition: qdom.h:243

◆ 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 2069 of file qdom.cpp.

2070 {
2071  impl = n.impl;
2072  if (impl)
2073  impl->ref.ref();
2074 }
bool ref()
Atomically increments the value of this QAtomicInt.
QAtomicInt ref
Definition: qdom.cpp:191
QDomNodePrivate * impl
Definition: qdom.h:243

◆ ~QDomNode()

QDomNode::~QDomNode ( )

Destroys the object and frees its resources.

Definition at line 2143 of file qdom.cpp.

2144 {
2145  if (impl && !impl->ref.deref())
2146  delete impl;
2147 }
QAtomicInt ref
Definition: qdom.cpp:191
bool deref()
Atomically decrements the value of this QAtomicInt.
QDomNodePrivate * impl
Definition: qdom.h:243

◆ QDomNode() [3/3]

QDomNode::QDomNode ( QDomNodePrivate n)
protected

Constructs a new node for the data n.

Warning
This function is not part of the public interface.

Definition at line 2082 of file qdom.cpp.

2083 {
2084  impl = n;
2085  if (impl)
2086  impl->ref.ref();
2087 }
bool ref()
Atomically increments the value of this QAtomicInt.
QAtomicInt ref
Definition: qdom.cpp:191
QDomNodePrivate * impl
Definition: qdom.h:243

Functions

◆ 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 null node on failure.

Calling this function on a null node(created, for example, with the default constructor) does nothing and returns a 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 2655 of file qdom.cpp.

Referenced by QDomImplementation::createDocument().

2656 {
2657  if (!impl) {
2658  qWarning("Calling appendChild() on a null node does nothing.");
2659  return QDomNode();
2660  }
2661  return QDomNode(IMPL->appendChild(newChild.impl));
2662 }
QDomNode()
Constructs a null node.
Definition: qdom.cpp:2057
Q_CORE_EXPORT void qWarning(const char *,...)
QDomNodePrivate * impl
Definition: qdom.h:243
#define IMPL
Definition: qdom.cpp:6666

◆ attributes()

QDomNamedNodeMap QDomNode::attributes ( ) const

Returns a named node map of all attributes.

Attributes are only provided for QDomElement.

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

Definition at line 2370 of file qdom.cpp.

Referenced by QDomElement::setAttributeNS().

2371 {
2372  if (!impl || !impl->isElement())
2373  return QDomNamedNodeMap();
2374 
2375  return QDomNamedNodeMap(static_cast<QDomElementPrivate *>(impl)->attributes());
2376 }
QDomNamedNodeMap attributes() const
Returns a named node map of all attributes.
Definition: qdom.cpp:2370
virtual bool isElement() const
Definition: qdom.cpp:175
friend class QDomNamedNodeMap
Definition: qdom.h:250
QDomNodePrivate * impl
Definition: qdom.h:243

◆ 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>

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 2290 of file qdom.cpp.

2291 {
2292  if (!impl)
2293  return QDomNodeList();
2294  return QDomNodeList(new QDomNodeListPrivate(impl));
2295 }
friend class QDomNodeList
Definition: qdom.h:249
QDomNodePrivate * impl
Definition: qdom.h:243

◆ clear()

void QDomNode::clear ( void  )

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 2690 of file qdom.cpp.

2691 {
2692  if (impl && !impl->ref.deref())
2693  delete impl;
2694  impl = 0;
2695 }
QAtomicInt ref
Definition: qdom.cpp:191
bool deref()
Atomically decrements the value of this QAtomicInt.
QDomNodePrivate * impl
Definition: qdom.h:243

◆ 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 2396 of file qdom.cpp.

2397 {
2398  if (!impl)
2399  return QDomNode();
2400  return QDomNode(IMPL->cloneNode(deep));
2401 }
QDomNode()
Constructs a null node.
Definition: qdom.cpp:2057
QDomNodePrivate * impl
Definition: qdom.h:243
#define IMPL
Definition: qdom.cpp:6666

◆ columnNumber()

int QDomNode::columnNumber ( ) const

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

Since
4.1

Otherwise, -1 is returned.

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

Definition at line 3091 of file qdom.cpp.

3092 {
3093  return impl ? impl->columnNumber : -1;
3094 }
int columnNumber
Definition: qdom.cpp:206
QDomNodePrivate * impl
Definition: qdom.h:243

◆ firstChild()

QDomNode QDomNode::firstChild ( ) const

Returns the first child of the node.

If there is no child node, a null node is returned. Changing the returned node will also change the node in the document tree.

See also
lastChild() childNodes()

Definition at line 2304 of file qdom.cpp.

Referenced by QDBusXmlParser::object(), and QDBusXmlParser::objectTree().

2305 {
2306  if (!impl)
2307  return QDomNode();
2308  return QDomNode(IMPL->first);
2309 }
QDomNode()
Constructs a null node.
Definition: qdom.cpp:2057
QDomNodePrivate * impl
Definition: qdom.h:243
#define IMPL
Definition: qdom.cpp:6666

◆ firstChildElement()

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

Returns the first child element with tag name tagName if tagName is non-empty; otherwise returns the first child element.

Returns a null element if no such child exists.

See also
lastChildElement() previousSiblingElement() nextSiblingElement()

Definition at line 2990 of file qdom.cpp.

Referenced by QDBusXmlParser::QDBusXmlParser().

2991 {
2992  for (QDomNode child = firstChild(); !child.isNull(); child = child.nextSibling()) {
2993  if (child.isElement()) {
2994  QDomElement elt = child.toElement();
2995  if (tagName.isEmpty() || elt.tagName() == tagName)
2996  return elt;
2997  }
2998  }
2999  return QDomElement();
3000 }
QString tagName() const
Returns the tag name of this element.
Definition: qdom.cpp:4871
QDomNode firstChild() const
Returns the first child of the node.
Definition: qdom.cpp:2304
QDomElement toElement() const
Converts a QDomNode into a QDomElement.
Definition: qdom.cpp:7449
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
The QDomNode class is the base class for all the nodes in a DOM tree.
Definition: qdom.h:128
bool isNull() const
Returns true if this node is null (i.e.
Definition: qdom.cpp:2679
The QDomElement class represents one element in the DOM tree.
Definition: qdom.h:476

◆ hasAttributes()

bool QDomNode::hasAttributes ( ) const

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

See also
attributes()

Definition at line 2521 of file qdom.cpp.

2522 {
2523  if (!impl || !impl->isElement())
2524  return false;
2525  return static_cast<QDomElementPrivate *>(impl)->hasAttributes();
2526 }
virtual bool isElement() const
Definition: qdom.cpp:175
QDomNodePrivate * impl
Definition: qdom.h:243
bool hasAttributes() const
Returns true if the node has attributes; otherwise returns false.
Definition: qdom.cpp:2521

◆ hasChildNodes()

bool QDomNode::hasChildNodes ( ) const

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

Definition at line 2668 of file qdom.cpp.

2669 {
2670  if (!impl)
2671  return false;
2672  return IMPL->first != 0;
2673 }
QDomNodePrivate * impl
Definition: qdom.h:243
#define IMPL
Definition: qdom.cpp:6666

◆ 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 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 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 2579 of file qdom.cpp.

2580 {
2581  if (!impl)
2582  return QDomNode();
2583  return QDomNode(IMPL->insertAfter(newChild.impl, refChild.impl));
2584 }
QDomNode()
Constructs a null node.
Definition: qdom.cpp:2057
QDomNodePrivate * impl
Definition: qdom.h:243
#define IMPL
Definition: qdom.cpp:6666

◆ 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 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 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 2550 of file qdom.cpp.

2551 {
2552  if (!impl)
2553  return QDomNode();
2554  return QDomNode(IMPL->insertBefore(newChild.impl, refChild.impl));
2555 }
QDomNode()
Constructs a null node.
Definition: qdom.cpp:2057
QDomNodePrivate * impl
Definition: qdom.h:243
#define IMPL
Definition: qdom.cpp:6666

◆ 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 2781 of file qdom.cpp.

2782 {
2783  if(impl)
2784  return impl->isAttr();
2785  return false;
2786 }
virtual bool isAttr() const
Definition: qdom.cpp:170
QDomNodePrivate * impl
Definition: qdom.h:243

◆ 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 2798 of file qdom.cpp.

2799 {
2800  if(impl)
2801  return impl->isCDATASection();
2802  return false;
2803 }
virtual bool isCDATASection() const
Definition: qdom.cpp:171
QDomNodePrivate * impl
Definition: qdom.h:243

◆ 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 2958 of file qdom.cpp.

2959 {
2960  if (impl)
2961  return impl->isCharacterData();
2962  return false;
2963 }
virtual bool isCharacterData() const
Definition: qdom.cpp:181
QDomNodePrivate * impl
Definition: qdom.h:243

◆ 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 2973 of file qdom.cpp.

2974 {
2975  if (impl)
2976  return impl->isComment();
2977  return false;
2978 }
QDomNodePrivate * impl
Definition: qdom.h:243
virtual bool isComment() const
Definition: qdom.cpp:182

◆ 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 2830 of file qdom.cpp.

2831 {
2832  if(impl)
2833  return impl->isDocument();
2834  return false;
2835 }
QDomNodePrivate * impl
Definition: qdom.h:243
virtual bool isDocument() const
Definition: qdom.cpp:173

◆ 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 2815 of file qdom.cpp.

2816 {
2817  if(impl)
2818  return impl->isDocumentFragment();
2819  return false;
2820 }
QDomNodePrivate * impl
Definition: qdom.h:243
virtual bool isDocumentFragment() const
Definition: qdom.cpp:172

◆ 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 2847 of file qdom.cpp.

2848 {
2849  if(impl)
2850  return impl->isDocumentType();
2851  return false;
2852 }
QDomNodePrivate * impl
Definition: qdom.h:243
virtual bool isDocumentType() const
Definition: qdom.cpp:174

◆ 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 2862 of file qdom.cpp.

2863 {
2864  if(impl)
2865  return impl->isElement();
2866  return false;
2867 }
virtual bool isElement() const
Definition: qdom.cpp:175
QDomNodePrivate * impl
Definition: qdom.h:243

◆ 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 2909 of file qdom.cpp.

2910 {
2911  if(impl)
2912  return impl->isEntity();
2913  return false;
2914 }
virtual bool isEntity() const
Definition: qdom.cpp:178
QDomNodePrivate * impl
Definition: qdom.h:243

◆ 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 2879 of file qdom.cpp.

2880 {
2881  if(impl)
2882  return impl->isEntityReference();
2883  return false;
2884 }
QDomNodePrivate * impl
Definition: qdom.h:243
virtual bool isEntityReference() const
Definition: qdom.cpp:176

◆ 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 2924 of file qdom.cpp.

2925 {
2926  if(impl)
2927  return impl->isNotation();
2928  return false;
2929 }
virtual bool isNotation() const
Definition: qdom.cpp:179
QDomNodePrivate * impl
Definition: qdom.h:243

◆ 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 2679 of file qdom.cpp.

Referenced by QDomImplementation::createDocument(), firstChildElement(), QDBusXmlParser::interfaces(), lastChildElement(), nextSiblingElement(), QDBusXmlParser::object(), QDBusXmlParser::objectTree(), parseAnnotations(), parseArgs(), previousSiblingElement(), and removeChild().

2680 {
2681  return (impl == 0);
2682 }
QDomNodePrivate * impl
Definition: qdom.h:243

◆ 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 2941 of file qdom.cpp.

2942 {
2943  if(impl)
2944  return impl->isProcessingInstruction();
2945  return false;
2946 }
QDomNodePrivate * impl
Definition: qdom.h:243
virtual bool isProcessingInstruction() const
Definition: qdom.cpp:180

◆ 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 2423 of file qdom.cpp.

2424 {
2426  return i.hasFeature(feature, version);
2427 }
bool hasFeature(const QString &feature, const QString &version) const
The function returns true if QDom implements the requested version of a feature; otherwise returns fa...
Definition: qdom.cpp:995
The QDomImplementation class provides information about the features of the DOM implementation.
Definition: qdom.h:99

◆ 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 2894 of file qdom.cpp.

2895 {
2896  if(impl)
2897  return impl->isText();
2898  return false;
2899 }
virtual bool isText() const
Definition: qdom.cpp:177
QDomNodePrivate * impl
Definition: qdom.h:243

◆ lastChild()

QDomNode QDomNode::lastChild ( ) const

Returns the last child of the node.

If there is no child node, a null node is returned. Changing the returned node will also change the node in the document tree.

See also
firstChild() childNodes()

Definition at line 2318 of file qdom.cpp.

2319 {
2320  if (!impl)
2321  return QDomNode();
2322  return QDomNode(IMPL->last);
2323 }
QDomNode()
Constructs a null node.
Definition: qdom.cpp:2057
QDomNodePrivate * impl
Definition: qdom.h:243
#define IMPL
Definition: qdom.cpp:6666

◆ lastChildElement()

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

Returns the last child element with tag name tagName if tagName is non-empty; otherwise returns the last child element.

Returns a null element if no such child exists.

See also
firstChildElement() previousSiblingElement() nextSiblingElement()

Definition at line 3010 of file qdom.cpp.

3011 {
3012  for (QDomNode child = lastChild(); !child.isNull(); child = child.previousSibling()) {
3013  if (child.isElement()) {
3014  QDomElement elt = child.toElement();
3015  if (tagName.isEmpty() || elt.tagName() == tagName)
3016  return elt;
3017  }
3018  }
3019  return QDomElement();
3020 }
QString tagName() const
Returns the tag name of this element.
Definition: qdom.cpp:4871
QDomElement toElement() const
Converts a QDomNode into a QDomElement.
Definition: qdom.cpp:7449
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
The QDomNode class is the base class for all the nodes in a DOM tree.
Definition: qdom.h:128
bool isNull() const
Returns true if this node is null (i.e.
Definition: qdom.cpp:2679
QDomNode lastChild() const
Returns the last child of the node.
Definition: qdom.cpp:2318
The QDomElement class represents one element in the DOM tree.
Definition: qdom.h:476

◆ lineNumber()

int QDomNode::lineNumber ( ) const

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

Since
4.1

Otherwise, -1 is returned.

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

Definition at line 3074 of file qdom.cpp.

3075 {
3076  return impl ? impl->lineNumber : -1;
3077 }
QDomNodePrivate * impl
Definition: qdom.h:243
int lineNumber
Definition: qdom.cpp:205

◆ 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 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() QDomDocument::createAttributeNS()

Definition at line 2509 of file qdom.cpp.

2510 {
2511  if (!impl || IMPL->createdWithDom1Interface)
2512  return QString();
2513  return IMPL->name;
2514 }
The QString class provides a Unicode character string.
Definition: qstring.h:83
QDomNodePrivate * impl
Definition: qdom.h:243
#define IMPL
Definition: qdom.cpp:6666

◆ 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 null node is returned.

See also
nodeName()

Definition at line 2706 of file qdom.cpp.

2707 {
2708  if (!impl)
2709  return QDomNode();
2710  return QDomNode(impl->namedItem(name));
2711 }
QDomNode()
Constructs a null node.
Definition: qdom.cpp:2057
QDomNodePrivate * namedItem(const QString &name)
Definition: qdom.cpp:1554
QDomNodePrivate * impl
Definition: qdom.h:243

◆ 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 ElementNode or 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 2441 of file qdom.cpp.

2442 {
2443  if (!impl)
2444  return QString();
2445  return IMPL->namespaceURI;
2446 }
The QString class provides a Unicode character string.
Definition: qstring.h:83
QDomNodePrivate * impl
Definition: qdom.h:243
#define IMPL
Definition: qdom.cpp:6666

◆ 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>

and this QDomNode represents the

tag, nextSibling() will return the node representing the

tag. previousSibling()

Definition at line 2354 of file qdom.cpp.

2355 {
2356  if (!impl)
2357  return QDomNode();
2358  return QDomNode(IMPL->next);
2359 }
QDomNode()
Constructs a null node.
Definition: qdom.cpp:2057
QDomNodePrivate * impl
Definition: qdom.h:243
#define IMPL
Definition: qdom.cpp:6666

◆ nextSiblingElement()

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

Returns the next sibling element with tag name tagName if tagName is non-empty; otherwise returns any next sibling element.

Returns a null element if no such sibling exists.

See also
firstChildElement() previousSiblingElement() lastChildElement()

Definition at line 3030 of file qdom.cpp.

3031 {
3032  for (QDomNode sib = nextSibling(); !sib.isNull(); sib = sib.nextSibling()) {
3033  if (sib.isElement()) {
3034  QDomElement elt = sib.toElement();
3035  if (tagName.isEmpty() || elt.tagName() == tagName)
3036  return elt;
3037  }
3038  }
3039  return QDomElement();
3040 }
QString tagName() const
Returns the tag name of this element.
Definition: qdom.cpp:4871
QDomElement toElement() const
Converts a QDomNode into a QDomElement.
Definition: qdom.cpp:7449
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
The QDomNode class is the base class for all the nodes in a DOM tree.
Definition: qdom.h:128
bool isNull() const
Returns true if this node is null (i.e.
Definition: qdom.cpp:2679
The QDomElement class represents one element in the DOM tree.
Definition: qdom.h:476
QDomNode nextSibling() const
Returns the next sibling in the document tree.
Definition: qdom.cpp:2354

◆ nodeName()

QString QDomNode::nodeName ( ) const

Returns the name of the node.

The meaning of the name depends on the subclass:

Name Meaning
QDomAttr The name of the attribute
QDomCDATASection The string "#cdata-section"
QDomComment The string "#comment"
QDomDocument The string "#document"
QDomDocumentFragment The string "#document-fragment"
QDomDocumentType The name of the document type
QDomElement The tag name
QDomEntity The name of the entity
QDomEntityReference The name of the referenced entity
QDomNotation The name of the notation
QDomProcessingInstruction The target of the processing instruction
QDomText The string "#text"

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 2178 of file qdom.cpp.

2179 {
2180  if (!impl)
2181  return QString();
2182 
2183  if (!IMPL->prefix.isEmpty())
2184  return IMPL->prefix + QLatin1Char(':') + IMPL->name;
2185  return IMPL->name;
2186 }
The QString class provides a Unicode character string.
Definition: qstring.h:83
QDomNodePrivate * impl
Definition: qdom.h:243
#define IMPL
Definition: qdom.cpp:6666
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ 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 2256 of file qdom.cpp.

Referenced by QDomCharacterData::nodeType().

2257 {
2258  if (!impl)
2259  return QDomNode::BaseNode;
2260  return IMPL->nodeType();
2261 }
QDomNodePrivate * impl
Definition: qdom.h:243
#define IMPL
Definition: qdom.cpp:6666

◆ nodeValue()

QString QDomNode::nodeValue ( ) const

Returns the value of the node.

The meaning of the value depends on the subclass:

Name Meaning
QDomAttr The attribute value
QDomCDATASection The content of the CDATA section
QDomComment The comment
QDomProcessingInstruction The data of the processing instruction
QDomText The text

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

See also
setNodeValue() nodeName()

Definition at line 2206 of file qdom.cpp.

2207 {
2208  if (!impl)
2209  return QString();
2210  return IMPL->value;
2211 }
The QString class provides a Unicode character string.
Definition: qstring.h:83
QDomNodePrivate * impl
Definition: qdom.h:243
#define IMPL
Definition: qdom.cpp:6666

◆ 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 2409 of file qdom.cpp.

2410 {
2411  if (!impl)
2412  return;
2413  IMPL->normalize();
2414 }
QDomNodePrivate * impl
Definition: qdom.h:243
#define IMPL
Definition: qdom.cpp:6666

◆ 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 2135 of file qdom.cpp.

2136 {
2137  return (impl != n.impl);
2138 }
QDomNodePrivate * impl
Definition: qdom.h:243

◆ 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 2096 of file qdom.cpp.

Referenced by QDomDocument::operator=(), QDomDocumentFragment::operator=(), QDomCharacterData::operator=(), QDomAttr::operator=(), QDomComment::operator=(), and QDomCDATASection::operator=().

2097 {
2098  if (n.impl)
2099  n.impl->ref.ref();
2100  if (impl && !impl->ref.deref())
2101  delete impl;
2102  impl = n.impl;
2103  return *this;
2104 }
bool ref()
Atomically increments the value of this QAtomicInt.
QAtomicInt ref
Definition: qdom.cpp:191
bool deref()
Atomically decrements the value of this QAtomicInt.
QDomNodePrivate * impl
Definition: qdom.h:243

◆ 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 2126 of file qdom.cpp.

2127 {
2128  return (impl == n.impl);
2129 }
QDomNodePrivate * impl
Definition: qdom.h:243

◆ ownerDocument()

QDomDocument QDomNode::ownerDocument ( ) const

Returns the document to which this node belongs.

Definition at line 2381 of file qdom.cpp.

2382 {
2383  if (!impl)
2384  return QDomDocument();
2385  return QDomDocument(IMPL->ownerDocument());
2386 }
friend class QDomDocument
Definition: qdom.h:247
QDomNodePrivate * impl
Definition: qdom.h:243
#define IMPL
Definition: qdom.cpp:6666

◆ 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 2267 of file qdom.cpp.

2268 {
2269  if (!impl)
2270  return QDomNode();
2271  return QDomNode(IMPL->parent());
2272 }
QDomNode()
Constructs a null node.
Definition: qdom.cpp:2057
QDomNodePrivate * impl
Definition: qdom.h:243
#define IMPL
Definition: qdom.cpp:6666

◆ 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 ElementNode or 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 2469 of file qdom.cpp.

2470 {
2471  if (!impl)
2472  return QString();
2473  return IMPL->prefix;
2474 }
The QString class provides a Unicode character string.
Definition: qstring.h:83
QDomNodePrivate * impl
Definition: qdom.h:243
#define IMPL
Definition: qdom.cpp:6666

◆ 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 2336 of file qdom.cpp.

2337 {
2338  if (!impl)
2339  return QDomNode();
2340  return QDomNode(IMPL->prev);
2341 }
QDomNode()
Constructs a null node.
Definition: qdom.cpp:2057
QDomNodePrivate * impl
Definition: qdom.h:243
#define IMPL
Definition: qdom.cpp:6666

◆ previousSiblingElement()

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

Returns the previous sibilng element with tag name tagName if tagName is non-empty; otherwise returns any previous sibling element.

Returns a null element if no such sibling exists.

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

Definition at line 3050 of file qdom.cpp.

3051 {
3052  for (QDomNode sib = previousSibling(); !sib.isNull(); sib = sib.previousSibling()) {
3053  if (sib.isElement()) {
3054  QDomElement elt = sib.toElement();
3055  if (tagName.isEmpty() || elt.tagName() == tagName)
3056  return elt;
3057  }
3058  }
3059  return QDomElement();
3060 }
QString tagName() const
Returns the tag name of this element.
Definition: qdom.cpp:4871
QDomElement toElement() const
Converts a QDomNode into a QDomElement.
Definition: qdom.cpp:7449
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
The QDomNode class is the base class for all the nodes in a DOM tree.
Definition: qdom.h:128
bool isNull() const
Returns true if this node is null (i.e.
Definition: qdom.cpp:2679
QDomNode previousSibling() const
Returns the previous sibling in the document tree.
Definition: qdom.cpp:2336
The QDomElement class represents one element in the DOM tree.
Definition: qdom.h:476

◆ 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 null node on failure.

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

Definition at line 2618 of file qdom.cpp.

2619 {
2620  if (!impl)
2621  return QDomNode();
2622 
2623  if (oldChild.isNull())
2624  return QDomNode();
2625 
2626  return QDomNode(IMPL->removeChild(oldChild.impl));
2627 }
QDomNode()
Constructs a null node.
Definition: qdom.cpp:2057
QDomNodePrivate * impl
Definition: qdom.h:243
#define IMPL
Definition: qdom.cpp:6666
bool isNull() const
Returns true if this node is null (i.e.
Definition: qdom.cpp:2679

◆ 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 null node an failure.

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

Definition at line 2602 of file qdom.cpp.

2603 {
2604  if (!impl || !newChild.impl || !oldChild.impl)
2605  return QDomNode();
2606  return QDomNode(IMPL->replaceChild(newChild.impl, oldChild.impl));
2607 }
QDomNode()
Constructs a null node.
Definition: qdom.cpp:2057
QDomNodePrivate * impl
Definition: qdom.h:243
#define IMPL
Definition: qdom.cpp:6666

◆ save() [1/2]

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

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

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

If this node is a document node, the encoding of text stream str's encoding is set by treating a processing instruction by name "xml" as an XML declaration, if such a 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 the document contains invalid XML characters or characters that cannot be encoded in the given encoding, the result and behavior is undefined.

Definition at line 2728 of file qdom.cpp.

Referenced by QDBusXmlParser::interfaces(), QDBusXmlParser::object(), QDBusXmlParser::objectTree(), operator<<(), and QDomDocument::toString().

2729 {
2730  save(str, indent, QDomNode::EncodingFromDocument);
2731 }
void save(QTextStream &, int) const
Writes the XML representation of the node and all its children to the stream str. ...
Definition: qdom.cpp:2728

◆ save() [2/2]

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

If encodingPolicy is QDomNode::EncodingFromDocument, this function behaves as save(QTextStream &str, int indent).

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 str 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 2745 of file qdom.cpp.

2746 {
2747  if (!impl)
2748  return;
2749 
2750  if(isDocument())
2751  static_cast<const QDomDocumentPrivate *>(impl)->saveDocument(str, indent, encodingPolicy);
2752  else
2753  IMPL->save(str, 1, indent);
2754 }
bool isDocument() const
Returns true if the node is a document; otherwise returns false.
Definition: qdom.cpp:2830
QDomNodePrivate * impl
Definition: qdom.h:243
#define IMPL
Definition: qdom.cpp:6666

◆ setNodeValue()

void QDomNode::setNodeValue ( const QString v)

Sets the node's value to v.

See also
nodeValue()

Definition at line 2218 of file qdom.cpp.

2219 {
2220  if (!impl)
2221  return;
2222  IMPL->setNodeValue(v);
2223 }
QDomNodePrivate * impl
Definition: qdom.h:243
#define IMPL
Definition: qdom.cpp:6666

◆ 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 ElementNode or 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 2489 of file qdom.cpp.

2490 {
2491  if (!impl || IMPL->prefix.isNull())
2492  return;
2493  if (isAttr() || isElement())
2494  IMPL->prefix = pre;
2495 }
bool isElement() const
Returns true if the node is an element; otherwise returns false.
Definition: qdom.cpp:2862
QDomNodePrivate * impl
Definition: qdom.h:243
#define IMPL
Definition: qdom.cpp:6666
bool isAttr() const
Returns true if the node is an attribute; otherwise returns false.
Definition: qdom.cpp:2781

◆ toAttr()

QDomAttr QDomNode::toAttr ( ) const

Converts a QDomNode into a QDomAttr.

If the node is not an attribute, the returned object will be null.

See also
isAttr()

Definition at line 7379 of file qdom.cpp.

7380 {
7381  if (impl && impl->isAttr())
7382  return QDomAttr(((QDomAttrPrivate*)impl));
7383  return QDomAttr();
7384 }
virtual bool isAttr() const
Definition: qdom.cpp:170
QDomNodePrivate * impl
Definition: qdom.h:243
The QDomAttr class represents one attribute of a QDomElement.
Definition: qdom.h:449

◆ toCDATASection()

QDomCDATASection QDomNode::toCDATASection ( ) const

Converts a QDomNode into a QDomCDATASection.

If the node is not a CDATA section, the returned object will be null.

See also
isCDATASection()

Definition at line 7393 of file qdom.cpp.

7394 {
7395  if (impl && impl->isCDATASection())
7397  return QDomCDATASection();
7398 }
virtual bool isCDATASection() const
Definition: qdom.cpp:171
QDomNodePrivate * impl
Definition: qdom.h:243
The QDomCDATASection class represents an XML CDATA section.
Definition: qdom.h:572

◆ 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 null.

See also
isCharacterData()

Definition at line 7532 of file qdom.cpp.

7533 {
7534  if (impl && impl->isCharacterData())
7536  return QDomCharacterData();
7537 }
virtual bool isCharacterData() const
Definition: qdom.cpp:181
QDomNodePrivate * impl
Definition: qdom.h:243
The QDomCharacterData class represents a generic string in the DOM.
Definition: qdom.h:416

◆ toComment()

QDomComment QDomNode::toComment ( ) const

Converts a QDomNode into a QDomComment.

If the node is not a comment the returned object will be null.

See also
isComment()

Definition at line 7546 of file qdom.cpp.

7547 {
7548  if (impl && impl->isComment())
7549  return QDomComment(((QDomCommentPrivate*)impl));
7550  return QDomComment();
7551 }
QDomNodePrivate * impl
Definition: qdom.h:243
The QDomComment class represents an XML comment.
Definition: qdom.h:555
virtual bool isComment() const
Definition: qdom.cpp:182

◆ toDocument()

QDomDocument QDomNode::toDocument ( ) const

Converts a QDomNode into a QDomDocument.

If the node is not a document the returned object will be null.

See also
isDocument()

Definition at line 7421 of file qdom.cpp.

7422 {
7423  if (impl && impl->isDocument())
7425  return QDomDocument();
7426 }
friend class QDomDocument
Definition: qdom.h:247
QDomNodePrivate * impl
Definition: qdom.h:243
virtual bool isDocument() const
Definition: qdom.cpp:173

◆ toDocumentFragment()

QDomDocumentFragment QDomNode::toDocumentFragment ( ) const

Converts a QDomNode into a QDomDocumentFragment.

If the node is not a document fragment the returned object will be null.

See also
isDocumentFragment()

Definition at line 7407 of file qdom.cpp.

7408 {
7409  if (impl && impl->isDocumentFragment())
7411  return QDomDocumentFragment();
7412 }
The QDomDocumentFragment class is a tree of QDomNodes which is not usually a complete QDomDocument...
Definition: qdom.h:399
QDomNodePrivate * impl
Definition: qdom.h:243
virtual bool isDocumentFragment() const
Definition: qdom.cpp:172

◆ toDocumentType()

QDomDocumentType QDomNode::toDocumentType ( ) const

Converts a QDomNode into a QDomDocumentType.

If the node is not a document type the returned object will be null.

See also
isDocumentType()

Definition at line 7435 of file qdom.cpp.

7436 {
7437  if (impl && impl->isDocumentType())
7439  return QDomDocumentType();
7440 }
friend class QDomDocumentType
Definition: qdom.h:248
QDomNodePrivate * impl
Definition: qdom.h:243
virtual bool isDocumentType() const
Definition: qdom.cpp:174

◆ toElement()

QDomElement QDomNode::toElement ( ) const

Converts a QDomNode into a QDomElement.

If the node is not an element the returned object will be null.

See also
isElement()

Definition at line 7449 of file qdom.cpp.

Referenced by firstChildElement(), QDBusXmlParser::interfaces(), lastChildElement(), nextSiblingElement(), QDBusXmlParser::object(), QDBusXmlParser::objectTree(), parseAnnotations(), parseArgs(), and previousSiblingElement().

7450 {
7451  if (impl && impl->isElement())
7452  return QDomElement(((QDomElementPrivate*)impl));
7453  return QDomElement();
7454 }
virtual bool isElement() const
Definition: qdom.cpp:175
QDomNodePrivate * impl
Definition: qdom.h:243
The QDomElement class represents one element in the DOM tree.
Definition: qdom.h:476

◆ toEntity()

QDomEntity QDomNode::toEntity ( ) const

Converts a QDomNode into a QDomEntity.

If the node is not an entity the returned object will be null.

See also
isEntity()

Definition at line 7490 of file qdom.cpp.

7491 {
7492  if (impl && impl->isEntity())
7493  return QDomEntity(((QDomEntityPrivate*)impl));
7494  return QDomEntity();
7495 }
virtual bool isEntity() const
Definition: qdom.cpp:178
QDomNodePrivate * impl
Definition: qdom.h:243
The QDomEntity class represents an XML entity.
Definition: qdom.h:610

◆ toEntityReference()

QDomEntityReference QDomNode::toEntityReference ( ) const

Converts a QDomNode into a QDomEntityReference.

If the node is not an entity reference, the returned object will be null.

See also
isEntityReference()

Definition at line 7463 of file qdom.cpp.

7464 {
7465  if (impl && impl->isEntityReference())
7467  return QDomEntityReference();
7468 }
QDomNodePrivate * impl
Definition: qdom.h:243
The QDomEntityReference class represents an XML entity reference.
Definition: qdom.h:631
virtual bool isEntityReference() const
Definition: qdom.cpp:176

◆ toNotation()

QDomNotation QDomNode::toNotation ( ) const

Converts a QDomNode into a QDomNotation.

If the node is not a notation the returned object will be null.

See also
isNotation()

Definition at line 7504 of file qdom.cpp.

7505 {
7506  if (impl && impl->isNotation())
7508  return QDomNotation();
7509 }
virtual bool isNotation() const
Definition: qdom.cpp:179
The QDomNotation class represents an XML notation.
Definition: qdom.h:589
QDomNodePrivate * impl
Definition: qdom.h:243

◆ toProcessingInstruction()

QDomProcessingInstruction QDomNode::toProcessingInstruction ( ) const

Converts a QDomNode into a QDomProcessingInstruction.

If the node is not a processing instruction the returned object will be null.

See also
isProcessingInstruction()

Definition at line 7518 of file qdom.cpp.

7519 {
7520  if (impl && impl->isProcessingInstruction())
7522  return QDomProcessingInstruction();
7523 }
The QDomProcessingInstruction class represents an XML processing instruction.
Definition: qdom.h:648
QDomNodePrivate * impl
Definition: qdom.h:243
virtual bool isProcessingInstruction() const
Definition: qdom.cpp:180

◆ toText()

QDomText QDomNode::toText ( ) const

Converts a QDomNode into a QDomText.

If the node is not a text, the returned object will be null.

See also
isText()

Definition at line 7476 of file qdom.cpp.

7477 {
7478  if (impl && impl->isText())
7479  return QDomText(((QDomTextPrivate*)impl));
7480  return QDomText();
7481 }
The QDomText class represents text data in the parsed XML document.
Definition: qdom.h:534
virtual bool isText() const
Definition: qdom.cpp:177
QDomNodePrivate * impl
Definition: qdom.h:243

Friends and Related Functions

◆ 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 2765 of file qdom.cpp.

2766 {
2767  node.save(str, 1);
2768 
2769  return str;
2770 }
void save(QTextStream &, int) const
Writes the XML representation of the node and all its children to the stream str. ...
Definition: qdom.cpp:2728

◆ QDomDocument

friend class QDomDocument
friend

Definition at line 247 of file qdom.h.

Referenced by QDomDocument::nodeType().

◆ QDomDocumentType

friend class QDomDocumentType
friend

Definition at line 248 of file qdom.h.

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

◆ QDomNamedNodeMap

friend class QDomNamedNodeMap
friend

Definition at line 250 of file qdom.h.

◆ QDomNodeList

friend class QDomNodeList
friend

Definition at line 249 of file qdom.h.

Referenced by QDomDocument::elementsByTagName(), and QDomDocument::elementsByTagNameNS().

Properties

◆ impl

QDomNodePrivate* QDomNode::impl
protected

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