Qbs Manual | List of Built-in Services | DomXml Service

Qbs 1.11.0

# DomXml Service

The `DomXml` 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

      XmlDomDocument()

Creates an XML DOM root node that can contain one element.

### createCDATASection

      XmlDomDocument.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

      XmlDomDocument.createElement(tagName: string)

Creates an element that can contain other elements, CDATA sections, and text nodes.

### createTextNode

      XmlDomDocument.createTextNode(value: string)

Creates a text node that represents textual content in an element or attribute.

### documentElement

      XmlDomDocument.documentElement()

Returns the document element.

### load

      XmlDomDocument.load(filePath: string): void

Loads the document specified by `filePath`.

### save

      XmlDomDocument.save(filePath: string, indentation: int): void

Saves the document at the location specified by `filePath` with the indentation specified by `int`.

### setContent

      XmlDomDocument.setContent(content: string)

Returns the content of the document.

### toString

      XmlDomDocument.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

      XmlDomNode()

Creates an XML DOM node.

### appendChild

      XmlDomNode.appendChild(tagName: string)

Appends a new child node to the end of the list of children of a node.

### attribute

      XmlDomNode.attribute(name: string, defaultValue: string)

Returns the name and default value of the attribute.

### clear

      XmlDomNode.clear()

Clears the contents of the node.

### data

      XmlDomNode.data()

Returns the contents of the text node, CDATA section, or character data node.

### firstChild

      XmlDomNode.firstChild(tagName: string)

Returns the first child of a node.

### hasAttribute

      XmlDomNode.hasAttribute(name: string) boolean

Returns `true` if the node has the specified attribute.

### hasAttributes

      XmlDomNode.hasAttributes() boolean

Returns `true` if the node has attributes.

### hasChildNodes

      XmlDomNode.hasChildNodes() boolean

Returns `true` if the node has children.

### insertAfter

      XmlDomNode.insertAfter(newChild: tagName, refChild: tagName)

Inserts a new child node after the child node specified by `refChild`.

### insertBefore

      XmlDomNode.insertBefore(newChild: tagName, refChild: tagName)

Inserts a new child node before the child node specified by `refChild`.

### isCDATASection

      XmlDomNode.isCDATASection() boolean

Returns `true` if this is a CDATA section.

### isElement

      XmlDomNode.isElement() boolean

Returns `true` if this is an element.

### isText

      XmlDomNode.isText() boolean

Returns `true` if this is a text node.

### lastChild

      XmlDomNode.lastChild(tagName: string)

Returns the last child of a node.

### nextSibling

      XmlDomNode.nextSibling(tagName: string)

Returns the node immediately following a node.

### parentNode

      XmlDomNode.parentNode()

Returns the parent of the node.

### previousSibling

      XmlDomNode.previousSibling(tagName: string)

Returns the node before a node.

### removeChild

      XmlDomNode.removeChild(tagName: string)

Removes the child node.

### replaceChild

      XmlDomNode.replaceChild(newChild: tagName, oldChild: tagName)

Replaces a child node with another one.

### setAttribute

      XmlDomNode.setAttribute(name: string, value: string)

Sets the name and value of an attribute.

### setData

      XmlDomNode.setData(value: string): void

Sets the data of the node to a text node, CDATA section, or character data node.

### setTagName

      XmlDomNode.setTagName(tagName: string)

Sets the tag name of the node.

### tagName

      XmlDomNode.tagName()

Returns the tag name of the node.

### text

      XmlDomNode.text()

Returns the text of the node.