XML_APPEND_ELEMENT

Use the XML_APPEND_ELEMENT script function to attach a specific element of the open XML document to another element as a sub-element. Doing so moves the element.

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

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

Syntax

XML_APPEND_ELEMENT (Reference element, Element)

Script Function and Parameters

  • XML_APPEND_ELEMENT
    Attaches an existing XML element to another element

  • Reference element
    Reference to the element to which the element will be added
    Format: script literal or script variable

  • Element
    Reference to the element in front of which the other element will be inserted
    Format: script literal or script variable

Return Code

This script function returns the reference to the attached element.

Example

The following example opens the @Details structured documentation page of the own object as an XML document. In addition, the 'Sub-Child-C', which is located within 'Child2', is attached to the first element of the XML structure (Child1).

Screenshot of the @Details Structured Documentation page showing the Child1 element with Sub-Child-A and Sub-Child-B, the Child2 element with Sub-Child-C, and the Child3 element with Sub-Child-D

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

:IF &XMLDOCU# <>
""
:SET &FIRST# = XML_GET_FIRST_CHILD(&XMLDOCU#)
:SET &TOAPPEND# = XML_SELECT_NODE(&XMLDOCU#,"Child2/Sub-Child-C")

:SET &CLONECHILD# = XML_APPEND_ELEMENT(&FIRST#,&TOAPPEND#)

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

: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 the sub-elements that are now located within the 'Child1' element:

Screenshot of the activation report showing Sub-Child-A, Sub-Child-B and Sub-Child-D, all of which are included in the Child1 element.

See also: