Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
QDomDocument Class Reference

\reentrant More...

#include <qdom.h>

+ Inheritance diagram for QDomDocument:
+ Collaboration diagram for QDomDocument:

Classes

struct  ParseResult
 The struct is used to store the result of QDomDocument::setContent(). More...
 

Public Types

enum class  ParseOption { Default = 0x00 , UseNamespaceProcessing = 0x01 , PreserveSpacingOnlyNodes = 0x02 }
 
- Public Types inherited from QDomNode
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

 QDomDocument ()
 Constructs an empty document.
 
 QDomDocument (const QString &name)
 Creates a document and sets the name of the document type to name.
 
 QDomDocument (const QDomDocumentType &doctype)
 Creates a document with the document type doctype.
 
 QDomDocument (const QDomDocument &document)
 Constructs a copy of document.
 
QDomDocumentoperator= (const QDomDocument &other)
 Assigns other to this DOM document.
 
 ~QDomDocument ()
 Destroys the object and frees its resources.
 
QDomElement createElement (const QString &tagName)
 Creates a new element called tagName that can be inserted into the DOM tree, e.g.
 
QDomDocumentFragment createDocumentFragment ()
 Creates a new document fragment, that can be used to hold parts of the document, e.g.
 
QDomText createTextNode (const QString &data)
 Creates a text node for the string value that can be inserted into the document tree, e.g.
 
QDomComment createComment (const QString &data)
 Creates a new comment for the string value that can be inserted into the document, e.g.
 
QDomCDATASection createCDATASection (const QString &data)
 Creates a new CDATA section for the string value that can be inserted into the document, e.g.
 
QDomProcessingInstruction createProcessingInstruction (const QString &target, const QString &data)
 Creates a new processing instruction that can be inserted into the document, e.g.
 
QDomAttr createAttribute (const QString &name)
 Creates a new attribute called name that can be inserted into an element, e.g.
 
QDomEntityReference createEntityReference (const QString &name)
 Creates a new entity reference called name that can be inserted into the document, e.g.
 
QDomNodeList elementsByTagName (const QString &tagname) const
 Returns a QDomNodeList, that contains all the elements in the document with the name tagname.
 
QDomNode importNode (const QDomNode &importedNode, bool deep)
 Imports the node importedNode from another document to this document.
 
QDomElement createElementNS (const QString &nsURI, const QString &qName)
 Creates a new element with namespace support that can be inserted into the DOM tree.
 
QDomAttr createAttributeNS (const QString &nsURI, const QString &qName)
 Creates a new attribute with namespace support that can be inserted into an element.
 
QDomNodeList elementsByTagNameNS (const QString &nsURI, const QString &localName)
 Returns a QDomNodeList that contains all the elements in the document with the local name localName and a namespace URI of nsURI.
 
QDomElement elementById (const QString &elementId)
 Returns the element whose ID is equal to elementId.
 
QDomDocumentType doctype () const
 Returns the document type of this document.
 
QDomImplementation implementation () const
 Returns a QDomImplementation object.
 
QDomElement documentElement () const
 Returns the root element of the document.
 
QDomNode::NodeType nodeType () const
 Returns DocumentNode.
 
Q_WEAK_OVERLOAD ParseResult setContent (const QByteArray &data, ParseOptions options=ParseOption::Default)
 
ParseResult setContent (QAnyStringView data, ParseOptions options=ParseOption::Default)
 
ParseResult setContent (QIODevice *device, ParseOptions options=ParseOption::Default)
 
ParseResult setContent (QXmlStreamReader *reader, ParseOptions options=ParseOption::Default)
 
QString toString (int indent=1) const
 Converts the parsed document back to its textual representation.
 
QByteArray toByteArray (int indent=1) const
 Converts the parsed document back to its textual representation and returns a QByteArray containing the data encoded as UTF-8.
 
- Public Member Functions inherited from QDomNode
 QDomNode ()
 Constructs a \l{isNull()}{null} node.
 
 QDomNode (const QDomNode &node)
 Constructs a copy of node.
 
QDomNodeoperator= (const QDomNode &other)
 Assigns a copy of other to this DOM node.
 
bool operator== (const QDomNode &other) const
 Returns true if other and this DOM node are equal; otherwise returns false.
 
bool operator!= (const QDomNode &other) const
 Returns true if other 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 &value)
 Sets the node's value to value.
 
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
 

Friends

class QDomNode
 

Additional Inherited Members

- Protected Member Functions inherited from QDomNode
 QDomNode (QDomNodePrivate *)
 
- Protected Attributes inherited from QDomNode
QDomNodePrivateimpl
 

Detailed Description

\reentrant

The QDomDocument class represents an XML document.

\inmodule QtXml

The QDomDocument class represents the entire XML document. Conceptually, it is the root of the document tree, and provides the primary access to the document's data.

Since elements, text nodes, comments, processing instructions, etc., cannot exist outside the context of a document, the document class also contains the factory functions needed to create these objects. The node objects created have an ownerDocument() function which associates them with the document within whose context they were created. The DOM classes that will be used most often are QDomNode, QDomDocument, QDomElement and QDomText.

The parsed XML is represented internally by a tree of objects that can be accessed using the various QDom classes. All QDom classes only reference objects in the internal tree. The internal objects in the DOM tree will get deleted once the last QDom object referencing them or the QDomDocument itself is deleted.

Creation of elements, text nodes, etc. is done using the various factory functions provided in this class. Using the default constructors of the QDom classes will only result in empty objects that cannot be manipulated or inserted into the Document.

The QDomDocument class has several functions for creating document data, for example, createElement(), createTextNode(), createComment(), createCDATASection(), createProcessingInstruction(), createAttribute() and createEntityReference(). Some of these functions have versions that support namespaces, i.e. createElementNS() and createAttributeNS(). The createDocumentFragment() function is used to hold parts of the document; this is useful for manipulating for complex documents.

The entire content of the document is set with setContent(). This function parses the string it is passed as an XML document and creates the DOM tree that represents the document. The root element is available using documentElement(). The textual representation of the document can be obtained using toString().

Note
The DOM tree might end up reserving a lot of memory if the XML document is big. For such documents, the QXmlStreamReader class might be a better solution.

It is possible to insert a node from another document into the document using importNode().

You can obtain a list of all the elements that have a particular tag with elementsByTagName() or with elementsByTagNameNS().

The QDom classes are typically used as follows:

QDomDocument doc("mydocument");
QFile file("mydocument.xml");
return;
if (!doc.setContent(&file)) {
return;
}
// print out the element names of all elements that are direct children
// of the outermost element.
QDomElement docElem = doc.documentElement();
QDomNode n = docElem.firstChild();
while(!n.isNull()) {
QDomElement e = n.toElement(); // try to convert the node to an element.
if(!e.isNull()) {
cout << qPrintable(e.tagName()) << '\n'; // the node really is an element.
}
n = n.nextSibling();
}
// Here we append a new element to the end of the document
QDomElement elem = doc.createElement("img");
elem.setAttribute("src", "myimage.png");
docElem.appendChild(elem);

Once doc and elem go out of scope, the whole internal tree representing the XML document is deleted.

To create a document using DOM use code like this:

QDomElement root = doc.createElement("MyML");
doc.appendChild(root);
QDomElement tag = doc.createElement("Greeting");
QDomText t = doc.createTextNode("Hello World");
tag.appendChild(t);

For further information about the Document Object Model see the Document Object Model (DOM) \l{http://www.w3.org/TR/REC-DOM-Level-1/}{Level 1} and \l{http://www.w3.org/TR/DOM-Level-2-Core/}{Level 2 Core} Specifications.

See also
{DOM Bookmarks Application}

Definition at line 268 of file qdom.h.

Member Enumeration Documentation

◆ ParseOption

enum class QDomDocument::ParseOption
strong
Since
6.5

This enum describes the possible options that can be used when parsing an XML document using the setContent() method.

\value Default No parse options are set. \value UseNamespaceProcessing Namespace processing is enabled. \value PreserveSpacingOnlyNodes Text nodes containing only spacing characters are preserved.

See also
setContent()
Enumerator
Default 
UseNamespaceProcessing 
PreserveSpacingOnlyNodes 

Definition at line 271 of file qdom.h.

Constructor & Destructor Documentation

◆ QDomDocument() [1/4]

QDomDocument::QDomDocument ( )

Constructs an empty document.

Definition at line 6029 of file qdom.cpp.

References QDomNode::impl.

◆ QDomDocument() [2/4]

QDomDocument::QDomDocument ( const QString & name)
explicit

Creates a document and sets the name of the document type to name.

Definition at line 6038 of file qdom.cpp.

References QDomNode::impl.

◆ QDomDocument() [3/4]

QDomDocument::QDomDocument ( const QDomDocumentType & doctype)
explicit

Creates a document with the document type doctype.

See also
QDomImplementation::createDocumentType()

Definition at line 6049 of file qdom.cpp.

References doctype(), and QDomNode::impl.

+ Here is the call graph for this function:

◆ QDomDocument() [4/4]

QDomDocument::QDomDocument ( const QDomDocument & document)

Constructs a copy of document.

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

◆ ~QDomDocument()

QDomDocument::~QDomDocument ( )

Destroys the object and frees its resources.

Definition at line 6083 of file qdom.cpp.

Member Function Documentation

◆ createAttribute()

QDomAttr QDomDocument::createAttribute ( const QString & name)

Creates a new attribute called name that can be inserted into an element, e.g.

using QDomElement::setAttributeNode().

If name is not a valid XML name, the behavior of this function is governed by QDomImplementation::InvalidDataPolicy.

See also
createAttributeNS()

Definition at line 6604 of file qdom.cpp.

References IMPL, and QDomNode::impl.

◆ createAttributeNS()

QDomAttr QDomDocument::createAttributeNS ( const QString & nsURI,
const QString & qName )

Creates a new attribute with namespace support that can be inserted into an element.

The name of the attribute is qName and the namespace URI is nsURI. This function also sets QDomNode::prefix() and QDomNode::localName() to appropriate values (depending on qName).

If qName is not a valid XML name, the behavior of this function is governed by QDomImplementation::InvalidDataPolicy.

See also
createAttribute()

Definition at line 6749 of file qdom.cpp.

References IMPL, and QDomNode::impl.

◆ createCDATASection()

QDomCDATASection QDomDocument::createCDATASection ( const QString & value)

Creates a new CDATA section for the string value that can be inserted into the document, e.g.

using QDomNode::appendChild().

If value contains characters which cannot be stored in a CDATA section, the behavior of this function is governed by QDomImplementation::InvalidDataPolicy.

See also
QDomNode::appendChild(), QDomNode::insertBefore(), QDomNode::insertAfter()

Definition at line 6567 of file qdom.cpp.

References IMPL, and QDomNode::impl.

◆ createComment()

QDomComment QDomDocument::createComment ( const QString & value)

Creates a new comment for the string value that can be inserted into the document, e.g.

using QDomNode::appendChild().

If value contains characters which cannot be stored in an XML comment, the behavior of this function is governed by QDomImplementation::InvalidDataPolicy.

See also
QDomNode::appendChild(), QDomNode::insertBefore(), QDomNode::insertAfter()

Definition at line 6550 of file qdom.cpp.

References IMPL, and QDomNode::impl.

◆ createDocumentFragment()

QDomDocumentFragment QDomDocument::createDocumentFragment ( )

Creates a new document fragment, that can be used to hold parts of the document, e.g.

when doing complex manipulations of the document tree.

Definition at line 6517 of file qdom.cpp.

References IMPL, and QDomNode::impl.

◆ createElement()

QDomElement QDomDocument::createElement ( const QString & tagName)

Creates a new element called tagName that can be inserted into the DOM tree, e.g.

using QDomNode::appendChild().

If tagName is not a valid XML name, the behavior of this function is governed by QDomImplementation::InvalidDataPolicy.

See also
createElementNS(), QDomNode::appendChild(), QDomNode::insertBefore(), QDomNode::insertAfter()

Definition at line 6505 of file qdom.cpp.

References IMPL, and QDomNode::impl.

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

+ Here is the caller graph for this function:

◆ createElementNS()

QDomElement QDomDocument::createElementNS ( const QString & nsURI,
const QString & qName )

Creates a new element with namespace support that can be inserted into the DOM tree.

The name of the element is qName and the namespace URI is nsURI. This function also sets QDomNode::prefix() and QDomNode::localName() to appropriate values (depending on qName).

If qName is an empty string, returns a null element regardless of whether the invalid data policy is set.

See also
createElement()

Definition at line 6730 of file qdom.cpp.

References IMPL, and QDomNode::impl.

Referenced by QDomImplementation::createDocument().

+ Here is the caller graph for this function:

◆ createEntityReference()

QDomEntityReference QDomDocument::createEntityReference ( const QString & name)

Creates a new entity reference called name that can be inserted into the document, e.g.

using QDomNode::appendChild().

If name is not a valid XML name, the behavior of this function is governed by QDomImplementation::InvalidDataPolicy.

See also
QDomNode::appendChild(), QDomNode::insertBefore(), QDomNode::insertAfter()

Definition at line 6620 of file qdom.cpp.

References IMPL, and QDomNode::impl.

◆ createProcessingInstruction()

QDomProcessingInstruction QDomDocument::createProcessingInstruction ( const QString & target,
const QString & data )

Creates a new processing instruction that can be inserted into the document, e.g.

using QDomNode::appendChild(). This function sets the target for the processing instruction to target and the data to data.

If target is not a valid XML name, or data if contains characters which cannot appear in a processing instruction, the behavior of this function is governed by QDomImplementation::InvalidDataPolicy.

See also
QDomNode::appendChild(), QDomNode::insertBefore(), QDomNode::insertAfter()

Definition at line 6586 of file qdom.cpp.

References IMPL, and QDomNode::impl.

Referenced by XmlWriter::toXml().

+ Here is the caller graph for this function:

◆ createTextNode()

QDomText QDomDocument::createTextNode ( const QString & value)

Creates a text node for the string value that can be inserted into the document tree, e.g.

using QDomNode::appendChild().

If value contains characters which cannot be stored as character data of an XML document (even in the form of character references), the behavior of this function is governed by QDomImplementation::InvalidDataPolicy.

See also
QDomNode::appendChild(), QDomNode::insertBefore(), QDomNode::insertAfter()

Definition at line 6534 of file qdom.cpp.

References IMPL, and QDomNode::impl.

Referenced by DocAppend().

+ Here is the caller graph for this function:

◆ doctype()

QDomDocumentType QDomDocument::doctype ( ) const

Returns the document type of this document.

Definition at line 6468 of file qdom.cpp.

References IMPL, QDomNode::impl, and QDomNode::QDomDocumentType.

Referenced by QDomDocument().

+ Here is the caller graph for this function:

◆ documentElement()

QDomElement QDomDocument::documentElement ( ) const

Returns the root element of the document.

Definition at line 6488 of file qdom.cpp.

References IMPL, and QDomNode::impl.

Referenced by DomText(), and FileContent().

+ Here is the caller graph for this function:

◆ elementById()

QDomElement QDomDocument::elementById ( const QString & elementId)

Returns the element whose ID is equal to elementId.

If no element with the ID was found, this function returns a \l{QDomNode::isNull()}{null element}.

Since the QDomClasses do not know which attributes are element IDs, this function returns always a \l{QDomNode::isNull()}{null element}. This may change in a future version.

Definition at line 6779 of file qdom.cpp.

References qWarning.

◆ elementsByTagName()

QDomNodeList QDomDocument::elementsByTagName ( const QString & tagname) const

Returns a QDomNodeList, that contains all the elements in the document with the name tagname.

The order of the node list is the order they are encountered in a preorder traversal of the element tree.

See also
elementsByTagNameNS(), QDomElement::elementsByTagName()

Definition at line 6635 of file qdom.cpp.

References QDomNode::impl, and QDomNode::QDomNodeList.

◆ elementsByTagNameNS()

QDomNodeList QDomDocument::elementsByTagNameNS ( const QString & nsURI,
const QString & localName )

Returns a QDomNodeList that contains all the elements in the document with the local name localName and a namespace URI of nsURI.

The order of the node list is the order they are encountered in a preorder traversal of the element tree.

See also
elementsByTagName(), QDomElement::elementsByTagNameNS()

Definition at line 6764 of file qdom.cpp.

References QDomNode::impl, QDomNode::localName(), and QDomNode::QDomNodeList.

+ Here is the call graph for this function:

◆ implementation()

QDomImplementation QDomDocument::implementation ( ) const

Returns a QDomImplementation object.

Definition at line 6478 of file qdom.cpp.

References IMPL, and QDomNode::impl.

◆ importNode()

QDomNode QDomDocument::importNode ( const QDomNode & importedNode,
bool deep )

Imports the node importedNode from another document to this document.

importedNode remains in the original document; this function creates a copy that can be used within this document.

This function returns the imported node that belongs to this document. The returned node has no parent. It is not possible to import QDomDocument and QDomDocumentType nodes. In those cases this function returns a \l{QDomNode::isNull()}{null node}.

If importedNode is a \l{QDomNode::isNull()}{null node}, a null node is returned.

If deep is true, this function imports not only the node importedNode but its whole subtree; if it is false, only the importedNode is imported. The argument deep has no effect on QDomAttr and QDomEntityReference nodes, since the descendants of QDomAttr nodes are always imported and those of QDomEntityReference nodes are never imported.

The behavior of this function is slightly different depending on the node types: \table \header

  • Node Type
  • Behavior \row
  • QDomAttr
  • The owner element is set to 0 and the specified flag is set to true in the generated attribute. The whole subtree of importedNode is always imported for attribute nodes: deep has no effect. \row
  • QDomDocument
  • Document nodes cannot be imported. \row
  • QDomDocumentFragment
  • If deep is true, this function imports the whole document fragment; otherwise it only generates an empty document fragment. \row
  • QDomDocumentType
  • Document type nodes cannot be imported. \row
  • QDomElement
  • Attributes for which QDomAttr::specified() is true are also imported, other attributes are not imported. If deep is true, this function also imports the subtree of importedNode; otherwise it imports only the element node (and some attributes, see above). \row
  • QDomEntity
  • Entity nodes can be imported, but at the moment there is no way to use them since the document type is read-only in DOM level 2. \row
  • QDomEntityReference
  • Descendants of entity reference nodes are never imported: deep has no effect. \row
  • QDomNotation
  • Notation nodes can be imported, but at the moment there is no way to use them since the document type is read-only in DOM level 2. \row
  • QDomProcessingInstruction
  • The target and value of the processing instruction is copied to the new node. \row
  • QDomText
  • The text is copied to the new node. \row
  • QDomCDATASection
  • The text is copied to the new node. \row
  • QDomComment
  • The text is copied to the new node. \endtable
See also
QDomElement::setAttribute(), QDomNode::insertBefore(), QDomNode::insertAfter(), QDomNode::replaceChild(), QDomNode::removeChild(), QDomNode::appendChild()

Definition at line 6709 of file qdom.cpp.

References IMPL, QDomNode::impl, and QDomNode.

◆ nodeType()

QDomNode::NodeType QDomDocument::nodeType ( ) const
inline

Returns DocumentNode.

Definition at line 316 of file qdom.h.

◆ operator=()

QDomDocument & QDomDocument::operator= ( const QDomDocument & other)
default

Assigns other to this DOM document.

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

◆ setContent() [1/4]

ParseResult QDomDocument::setContent ( const QByteArray & data,
ParseOptions options = ParseOption::Default )
inline

Definition at line 338 of file qdom.h.

Referenced by FileContent(), setContent(), and setContent().

+ Here is the caller graph for this function:

◆ setContent() [2/4]

QDomDocument::ParseResult QDomDocument::setContent ( QAnyStringView data,
ParseOptions options = ParseOption::Default )

Definition at line 6399 of file qdom.cpp.

References setContent(), and UseNamespaceProcessing.

+ Here is the call graph for this function:

◆ setContent() [3/4]

QDomDocument::ParseResult QDomDocument::setContent ( QIODevice * device,
ParseOptions options = ParseOption::Default )

Definition at line 6406 of file qdom.cpp.

References device, error, qPrintable, qWarning, QIODeviceBase::ReadOnly, setContent(), and UseNamespaceProcessing.

+ Here is the call graph for this function:

◆ setContent() [4/4]

QDomDocument::ParseResult QDomDocument::setContent ( QXmlStreamReader * reader,
ParseOptions options = ParseOption::Default )
Since
6.5

This function parses the XML document from the byte array data, string view text, IO device, or stream reader and sets it as the content of the document. It tries to detect the encoding of the document, in accordance with the XML specification. Returns the result of parsing in ParseResult, which explicitly converts to bool.

You can use the options parameter to specify different parsing options, for example, to enable namespace processing, etc.

By default, namespace processing is disabled. If it's disabled, the parser does no namespace processing when it reads the XML file. The functions QDomNode::prefix(), QDomNode::localName() and QDomNode::namespaceURI() return an empty string.

If namespace processing is enabled via the parse options, the parser recognizes namespaces in the XML file and sets the prefix name, local name and namespace URI to appropriate values. The functions QDomNode::prefix(), QDomNode::localName() and QDomNode::namespaceURI() return a string for all elements and attributes and return an empty string if the element or attribute has no prefix.

Text nodes consisting only of whitespace are stripped and won't appear in the QDomDocument. Since Qt 6.5, one can pass QDomDocument::ParseOption::PreserveSpacingOnlyNodes as a parse option, to specify that spacing-only text nodes must be preserved.

entity-refs

Note
The overload taking IO device will try to open it in read-only mode if it is not already open. In that case, the caller is responsible for calling close. This will change in Qt 7, which will no longer open the IO device. Applications should therefore open the device themselves before calling setContent().
See also
ParseResult, ParseOptions

Definition at line 6425 of file qdom.cpp.

References IMPL, and QDomNode::impl.

◆ toByteArray()

QByteArray QDomDocument::toByteArray ( int indent = 1) const

Converts the parsed document back to its textual representation and returns a QByteArray containing the data encoded as UTF-8.

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

See also
toString()

Definition at line 6457 of file qdom.cpp.

References toString(), and QString::toUtf8().

+ Here is the call graph for this function:

◆ toString()

QString QDomDocument::toString ( int indent = 1) const

Converts the parsed document back to its textual representation.

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

If indent is -1, no whitespace at all is added.

Definition at line 6440 of file qdom.cpp.

References QDomNode::save(), str, and QIODeviceBase::WriteOnly.

Referenced by DocAppend(), and toByteArray().

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

Friends And Related Symbol Documentation

◆ QDomNode

friend class QDomNode
friend

Definition at line 353 of file qdom.h.

Referenced by importNode().


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