XML_SET_ATTRIBUTE

Use the XML_SET_ATTRIBUTE script function to add an attribute to an XML element or change an existing attribute of an element that is located in the open XML document. You need to specify a reference to the element and the name and value of the attribute. If the attribute you specify cannot be found, it is added to the element. Only the element that is available in the 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)

Script Function and Parameters

  • XML_SET_ATTRIBUTE
    Adds a new attribute to an XML element or changes an existing one

  • Element
    Reference to the element whose attribute is changed or to which the new attribute is added.
    Format: script literal or script variable

  • Attribute
    Name of the attribute with an @ character at its beginning
    Format: script literal or script variable
    Important! A runtime error will occur if you do not add an @ character at the beginning.

  • Value
    Value of the attribute
    Format: script literal or script variable

Return Code

  • 0
    The attribute was successfully changed/added.

Example

The following example opens the @Details structured documentation page as an XML document and selects the 'Child' element. The new 'Attribute1' attribute is added to the element. If successfully added, the XML_SET_ATTRIBUTE script function is then read once more as a verification, and the 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: