JavaScript object: XML

The following JavaScript object is unique to Service Manager.

The XML() constructor creates an empty XML object where you can store and manipulate XML documents.

This object's methods do not use the Service Manager-defined global return codes.

Constructor

new XML();

Arguments

None

Properties

None

Methods

The following methods are valid for this object:

Defined method Description
setContent Creates an XML document from a string or file.
getParentNode Returns an XML object representing the parent node of the current node.
getFirstChildElement Returns an XML object representing the first child node of the current node.
getNextSiblingElement Returns an XML object representing the next node at the same level in the Document Object Model (DOM) tree as the current node.
getFirstAttribute Returns an XML object representing the first attribute of the current node.
getNextAttribute Returns an XML object representing the next attribute of the current node.
getNodeName Returns a string representing the name of the current element or attribute.
getName Returns a string representing the name of the current element or attribute.
getQualifiedName Returns a string representing the name of the current element or attribute including any namespace value.
getPrefix Returns a string representing the namespace value of the current element or attribute.
getNodeValue Returns a string representing the value of the current element.
getValue Returns a string representing the value of the current element.
setNodeValue Adds or updates the value of the current element.
setValue Adds or updates the value of the current element.
getNodeType Evaluates an XML object and returns an integer representing the XML DOM type of the current element or attribute.
isDocumentElement Returns true if the current element is the DOM document element.
getDocumentElement Creates an XML object containing the document element and all child elements from an XML object or XML string.
createNode Creates an XML node from an XML object.
appendNode Inserts an XML node into an XML object.
importNode Copies an XML node from one XML document to another.
addAttribute Inserts an XML attribute and attribute value into the current element.
getAttributeNode Returns an XML object containing an attribute node.
getAttributeValue Returns the value of the target attribute.
setAttributeValue Adds or updates an attribute value.
addElement Inserts an XML element as a child of the current element.
setText Adds or updates the value of the current element.
getText Returns a string representing the value of the current element.
toXMLString Converts an XML object into a valid XML string.
removeAttribute emoves an XML attribute from the current element.

Example

This example does the following:

  • Creates an XML object
  • Sets the content of the XML object to a local XML file

This example requires the following sample data:

  • A local XML file (for example, C:\test.xml which contains <document><parent1><child1 attribute1="a" /><child2 /></parent1><parent2><child3 /><child4 /></parent2></document>)
/* Instantiate an empty XML object */
var xmlObj = new XML();

/* Instantiate a variable containing the path to an XML file */
var xmlFile = "C:\\myxmldoc.xml";

/* Use setContent to make the XML object read and parse the XML file
*  If the setContent method fails, print an error message */
if ( ! xmlObj.setContent( xmlFile, true ) )
{
  print( "setContent failed. Unable to parse xml: " + xmlFile );
}