XML_TO_STRING

Use the XML_TO_STRING script function to retrieve and convert the XML structure of a specific element (handle) to a string. You can use the string that XML_TO_STRING returns for further processing by storing it in a script variable.

Syntax

XML_TO_STRING (Reference)

Script Function and Parameters

  • XML_TO_STRING
    Retrieves the XML of a specific element as a text

  • Reference
    Reference to the corresponding XML element. All sub-elements of the specified element are considered.
    Format: script literal or script variable
    Tips: References or handles let you identify and edit a position within the XML document. You can use the following script functions to retrieve handles:

    • XML_OPENReturns the very first handle, which refers to the root element.
    • XML_SELECT_NODE
      Returns the reference to the element you search or an empty string if the searched element does not exist.
    • XML_GET_FIRST_CHILD
      Returns the reference to the first sub-element of an element in an XML document.

Return Code

This script function returns the XML of the defined reference as a string.

Example

The following example opens the @Details structured documentation page as an XML document. The complete XML document is then converted to a string and stored in a script variable. In this script variable, you replace the 'test' string with 'prod.' Once the old XML document is closed, the new XML in the script variable is reopened as an XML document, and its elements (first-level elements) are written to the activation log in a loop.

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

:IF &XMLDOCU# <>
""
 

:SET &XMLSTRING# = XML_TO_STRING(&XMLDOCU#)
:SET &XMLSTRINGNEW# = STR_SUB(&XMLSTRING#,"test","prod")


:ENDIF
:XML_CLOSE &XMLDOCU#

:SET &XMLDOCU#=XML_OPEN(STRING,&XMLSTRINGNEW#)

:SET &ELEMENT# = XML_GET_FIRST_CHILD(&XMLDOCU#)
:WHILE &ELEMENT# <> ""
: SET &NAME# = XML_GET_NODE_NAME(&ELEMENT#)
: P 'Element: &NAME#'
: SET &ELEMENT# = XML_GET_NEXTSIBLING(&ELEMENT#)
:ENDWHILE

See also: