XML_APPEND_BEFORE

Use the XML_APPEND_BEFORE script function to insert a specific XML element before another element within the open XML document, thereby moving this element into the XML structure. The moved element is then located on the same level as the other element, the reference element.

Important!

  • The XML structure is modified in the memory only. You do not see the changes of XML_APPEND_BEFORE on the structured documentation page.

  • Do not move the element to the top level. The reference element cannot be located on the top level.

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

Syntax

XML_APPEND_BEFORE (ElementReference element)

Parameters

Parameter Description Format
Element Reference to the element to be moved. Script literal or script variable
Reference element Reference to the element in front of which you want to insert the Element. n.a.

Return Codes

This script function returns the reference to the inserted element.

Examples

The following example opens the @Details structured documentation page of the own object as an XML document. The script moves the original order of the existing elements. The 'Sub-Child1' element within 'Child' is moved before the 'Sub-Child3' element in 'Child2':

Screenshot showing the Structured Documentation page called "Details" of a Script object called "XML_APPEND_BEFORE"

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

:IF &XMLDOCU# <> ""

:   SET &ELEMENT1# = XML_SELECT_NODE(&XMLDOCU#,"Child/Sub-Child1")

:   SET &ELEMENT2# = XML_SELECT_NODE(&XMLDOCU#,"Child2/Sub-Child3")

:   SET &NEW# = XML_APPEND_BEFORE(&ELEMENT1#,&ELEMENT2#)

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

:   SET &ELEMENT# = XML_GET_FIRST_CHILD(&ELEMENT#)

:   WHILE &ELEMENT# <> ""

:      SET &NAME# = XML_GET_NODE_NAME(&ELEMENT#)

:      P 'Element: &NAME#'

:      SET &ELEMENT# = XML_GET_NEXTSIBLING(&ELEMENT#)

:   ENDWHILE

:ENDIF

:XML_CLOSE &XMLDOCU#

The activation report shows all elements located within 'Child2':

Screenshot of the last report of the XML_AOOEND_BEFORE Script object showing sub-child1 and sub-child3

See also: