Xml Service
The Xml
service enables you to access and manipulate XML Document Object Model (DOM) documents. The entire document is a document node, each XML element is an element node, the text paragraphs in the XML elements are text nodes, and each attribute is an attribute node.
XML DOM presents documents as tree structures. The contents of the nodes can be accessed in the tree. They can be modified or deleted, and new nodes can be created.
The nodes in the node tree have a hierarchical relationship to each other. The top node is called the root. Each node, except the root, has exactly one parent node, while it can have any number of children. Nodes with the same parent are called siblings.
XML DOM Document Node Operations
A document node represents an entire document. That is, the root of the DOM tree.
Constructor
Xml.DomDocument()
Creates an XML DOM root node that can contain one element.
createCDATASection
Xml.DomDocument.createCDATASection(value: string)
Creates a CDATA section that is not parsed by a parser. It can be used to include XML fragments without having to escape the delimiters, for example. Tags inside the section are not treated as markup nor are entities expanded.
createElement
Xml.DomDocument.createElement(tagName: string)
Creates an element that can contain other elements, CDATA sections, and text nodes.
createTextNode
Xml.DomDocument.createTextNode(value: string)
Creates a text node that represents textual content in an element or attribute.
documentElement
Xml.DomDocument.documentElement()
Returns the document element.
load
Xml.DomDocument.load(filePath: string): void
Loads the document specified by filePath
.
save
Xml.DomDocument.save(filePath: string, indentation: int): void
Saves the document at the location specified by filePath
with the indentation specified by int
.
setContent
Xml.DomDocument.setContent(content: string)
Returns the content of the document.
toString
Xml.DomDocument.toString(indentation: int)
Converts the document to a string with the indentation specified by int
.
XML DOM Node Operations
A node represents a single node in the document tree. There are several different types of nodes, such as element, attribute, and text nodes.
All objects inherit the node properties for handling parents and children, even if they cannot have parents or children. For example, attempting to add children to text nodes results in a DOM error.
Constructor
Xml.DomNode()
Creates an XML DOM node.
appendChild
Xml.DomNode.appendChild(tagName: string)
Appends a new child node to the end of the list of children of a node.
attribute
Xml.DomNode.attribute(name: string, defaultValue: string)
Returns the name and default value of the attribute.
clear
Xml.DomNode.clear()
Clears the contents of the node.
data
Xml.DomNode.data()
Returns the contents of the text node, CDATA section, or character data node.
firstChild
Xml.DomNode.firstChild(tagName: string)
Returns the first child of a node.
hasAttribute
Xml.DomNode.hasAttribute(name: string) boolean
Returns true
if the node has the specified attribute.
hasAttributes
Xml.DomNode.hasAttributes() boolean
Returns true
if the node has attributes.
hasChildNodes
Xml.DomNode.hasChildNodes() boolean
Returns true
if the node has children.
insertAfter
Xml.DomNode.insertAfter(newChild: tagName, refChild: tagName)
Inserts a new child node after the child node specified by refChild
.
insertBefore
Xml.DomNode.insertBefore(newChild: tagName, refChild: tagName)
Inserts a new child node before the child node specified by refChild
.
isCDATASection
Xml.DomNode.isCDATASection() boolean
Returns true
if this is a CDATA section.
isElement
Xml.DomNode.isElement() boolean
Returns true
if this is an element.
isText
Xml.DomNode.isText() boolean
Returns true
if this is a text node.
lastChild
Xml.DomNode.lastChild(tagName: string)
Returns the last child of a node.
nextSibling
Xml.DomNode.nextSibling(tagName: string)
Returns the node immediately following a node.
parentNode
Xml.DomNode.parentNode()
Returns the parent of the node.
previousSibling
Xml.DomNode.previousSibling(tagName: string)
Returns the node before a node.
removeChild
Xml.DomNode.removeChild(tagName: string)
Removes the child node.
replaceChild
Xml.DomNode.replaceChild(newChild: tagName, oldChild: tagName)
Replaces a child node with another one.
setAttribute
Xml.DomNode.setAttribute(name: string, value: string)
Sets the name and value of an attribute.
setData
Xml.DomNode.setData(value: string): void
Sets the data of the node to a text node, CDATA section, or character data node.
setTagName
Xml.DomNode.setTagName(tagName: string)
Sets the tag name of the node.
tagName
Xml.DomNode.tagName()
Returns the tag name of the node.
text
Xml.DomNode.text()
Returns the text of the node.
© 2023 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.