iTP Active Transaction Pages (iTP ATP) Programmer's Guide

XML for ATP Add-On Module
iTP Active Transaction Pages (iTP ATP) Programmer’s Guide522292-002
5-53
Methods
Output
2
1
setAttribute
Adds a new attribute. If an attribute with that name is already present in the element,
its value is changed to that of the value parameter. This value is a simple string; it is
not parsed as it is being set. So any markup (such as syntax to be recognized as an
entity reference) is treated as literal text and needs to be appropriately escaped by
the implementation when it is written out.
In order to assign an attribute value that contains entity references, you must:
1. Create an XMLDOMAttribute Object
node plus any XMLDOMText Object and
XMLDOMEntityReference Object
nodes
2. Build the appropriate subtree
3. Use setAttributeNode to assign it as the value of an attribute
Syntax
oXMLDOMElement.setAttribute(name, value)
Parameters
name – The name of the attribute to create or alter.
value – The value to set in string form.
Return Value
None.
ATPException
The following list shows the possible error-detail codes for the ATPException,
where error code is equal to ATP_ERR_DOM_EXCEPTION.
INVALID_CHARACTER_ERR(5): This error-detail code is raised if the
specified name contains an invalid character.
NO_MODIFICATION_ALLOWED_ERR(7): This error-detail code indicates
that the node is read-only.
Example
var doc = new XML.DOMDocument;
doc.load("sample.xml");
var root = doc.documentElement;
var node = root.childNodes.item(1).childNodes.item(1);
node.setAttribute("test", "true");
println(node.xml);