XML Object

The XML object provides a parsing function that operates on a string of XML-marked-up text, and that returns an XMLNode object that provides methods which allow the XML to be traversed and queried.

XMLNode XML.parse(markup)

This function parses the given string of XML markup and returns a document node object that represents the root of the document tree. If the parse fails a catchable exception is thrown.

Note that the XML is assumed to use the UTF-8 encoding (which is the default for XML files that don't specify an encoding), even if an encoding is specified that isn't UTF-8.

XMLNode xmlNode.firstChild

This read-only node property holds this node's first child—or a null node if this node has no children.

String xmlNode.getAttribute(attributeName)

This node method returns a string containing the value of the node's attributeName attribute. If the node doesn't have an attribute called attributeName, the method's behavior is undefined. If the attributeName is an empty string, a catchable exception is thrown. All of a node's attribute names can be retrieved using the ListOfString xmlNode.getAttributeNames() function.

Note: This function must only be called on element nodes—those nodes whose nodeType attribute's value is XML.ElementNode. Calling the function on non-element nodes will cause a catchable exception to be thrown.

ListOfString xmlNode.getAttributeNames()

This node method returns a list of strings containing the names of all the node's attributes. Any of these names can be used as the argument to the String xmlNode.getAttribute(attributeName) function to get the corresponding attribute's value.

Note: This function must only be called on element nodes—those nodes whose nodeType attribute's value is XML.ElementNode. Calling the function on non-element nodes will cause a catchable exception to be thrown.

Boolean xmlNode.hasAttribute(attributeName)

This function returns true if the node has an attribute called attributeName; otherwise it returns false.

Note: This function must only be called on element nodes—those nodes whose nodeType attribute's value is XML.ElementNode. Calling the function on non-element nodes will cause a catchable exception to be thrown.

ListOfXMLNode xmlNode.getElementsByTagName(tagName)

This function returns a list of XMLNode objects for the given tagName.

Note: This function must only be called on document or element nodes—a node whose nodeType property's value is XML.DocumentNode or XML.ElementNode respectively. Calling the function on other nodes will cause a catchable exception to be thrown.

XMLNode XMLNode.selectSingleNode(XPathExpression)

This function evaluates a given XPath.Expression on an XMLNode object's parent document and retrieves the first XMLNode object the evaluation returns, or (if given XPath exptession doesn't evaluate anything) null will be beturned.

jsTupelOfValues xmlNode.selectNodes(XPath.Expression)

This function evaluates an XPath.Expression on an XMLNode object's parent document and returns a list of XMLNode objects.

jsValue XMLNode.getSingleValueByXPath(XPathExpression)

This function evaluates a given XPath.Expression on an XMLNode object's parent document and retrieves the content of the first XMLNode object the evaluation returns. So return type varies, depending on the type of content the returned XMLNode object contains. If the evaluation won't return any nodes, it will return null.

jsTupelOfValues XMLNode.getValuesByXPath(XPath.Expression)

This function evaluates an XPath.Expression on an XMLNode object's parent document and returns a JavaScript tuple, which elements are either: directly that contents which are contained in the returned XMLNode objects, or, if evaluation may return XMLNode objects which contain just a subtree of even more XMLNode objects as children, these nodes then are contained in the tuple 'as are'.

Boolean xmlNode.isNull

This read-only node property is true if the node is a null node; otherwise it is false.

XMLNode xmlNode.nextSibling

This read-only node property holds this node's next sibling node (which will be a null node if this node has no next sibling).

String xmlNode.nodeName

This node property holds the node's name, which is the tag name for element nodes. For the document node the node name is always "<anonymous xml document>".

Integer xmlNode.nodeType

This node property holds the node's type as enum value. The possible type values are:

  • 0 : XML.DocumentNode
  • 1 : XML.ElementNode
  • 2 : XML.CommentNode
  • 3 : XML.UnknownType
  • 4 : XML.TextNode
  • 5 : XML.DeclarationNode

String xmlNode.nodeValue

This node property holds the node's value. The meaning depends on the type of the node as follows:

  • XML.CommentNode provides the comment text
  • XML.DeclarationNode provides an empty text
  • XML.DocumentNode provides the fixed text "<anonymous xml document>"
  • XML.TextNode provides the text string
  • XML.UnknownType provides the content of the tag

XMLNode xmlNode.parentNode

This node property holds the node's parent node or a null node if this node has no parent. (For example, the document node has no parent.)

String xmlNode.textContent

This node property holds the text contained within this node (which could be an empty string).

Note that this node property does not traverse its child nodes to produce a concatenation of all their texts. For example:

var documentNode = XML.parse("<a>Hello</a>");
var anchorNode = documentNode.firstChild;
test.verify(anchorNode.textContent == "Hello");

documentNode = XML.parse("<a><b>Hello</b></a>");
anchorNode = documentNode.firstChild;
test.verify(anchorNode.textContent == "");
var boldNode = anchorNode.firstChild;
test.verify(boldNode.textContent == "Hello");

Note: This function must only be called on element nodes—those nodes whose nodeType attribute's value is XML.ElementNode. Calling the function on non-element nodes will cause a catchable exception to be thrown.

String xmlNode.toXMLString()

This function returns an XML-formatted string representation of the XMLNode object including tags, attributes and child elements.

© 2024 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.

Search Results