XML_SET_ATTRIBUTE

Use the XML_SET_ATTRIBUTE script function to add an attribute to an XML element, or to change an existing attribute of an element in the open XML document. You specify a reference to the element together with the name and value of the attribute. If the specified attribute does not exist, it is added to the element. Only the element held in memory is modified; a Documentation page, for example, is not changed.

Tip: Use the XML_OPEN script function to open the XML document. For more information, see XML_OPEN.

Syntax

XML_SET_ATTRIBUTE (Element, Attribute, Value)

Parameters

Parameter Description Format
Element Reference to the element whose attribute is changed, or to which the new attribute is added. Script literal or script variable
Attribute Name of the attribute. Begin the name with an @ character.
Note: A runtime error occurs if the @ character is missing at the beginning.
Script literal or script variable
Value Value of the attribute Script literal or script variable

Return Codes

Return Value Condition
0 The attribute was successfully changed or added

Examples

The following example opens the @Details structured Documentation page as an XML document and selects the Child element. A new Attribute1 attribute is added to the element. If the attribute is added successfully, it is read back as a verification and its value is written to the activation report.

:SET &XMLDOCU# = XML_OPEN(DOCU,,"@Details")

:IF &XMLDOCU# <> ""

:   SET &ELEMENT# = XML_SELECT_NODE(&XMLDOCU#,"Child")

:   SET &RET# = XML_SET_ATTRIBUTE(&ELEMENT#,"@Attribute1","Value1")

:   IF &RET# = 0

:      SET &ATT# = XML_GET_ATTRIBUTE(&ELEMENT#,"@Attribute1")

:      P &ATT#

:   ENDIF

:ENDIF

:XML_CLOSE &XMLDOCU#

See also: