Automation Engine Script Guide > Ordered by Function > Read or Modify Objects > XML_CLONE_AND_RENAME

XML_CLONE_AND_RENAME

Script function: Duplicates and renames an XML element.

Syntax

XML_CLONE_AND_RENAME(Element, Name)

Syntax part

Description/format

Element

Reference to the element that should be duplicated.
Format: script literal or script variable

Name

New name of the duplicated element
Format: script literal or script variable


Return code

Reference to the new, duplicated element.

Notes

The script element duplicates an element of the XML document that is open (see script element XML_OPEN) and renames it. The duplicated element has to be appended to an element using the script function XML_APPEND_ELEMENT 

XML_CLONE_AND_RENAME duplicates the element but does not add it to any element. Use XML_APPEND_ELEMENT to append the duplicated element as subnode to another element.

All subordinate elements and values are taken into consideration during duplication.

The script element only copies the XML structure that is stored in the memory. The Documentation tab is not affected.

Please note that spaces are not permitted in the element name and lead to a runtime error.

Example

In the following example, the structured Documentation tab is opened and the 'SubChild3' element that is located in the 'Child2' parent element is duplicated with the name 'New_Element'. The sub-elements from 'Child2' will then be written in the activation report.

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

:IF &XMLDOCU# <>
""
:SET &TOCLONE# = XML_SELECT_NODE(&XMLDOCU#,"Child2/SubChild3")

:SET &CLONECHILD# = XML_CLONE_AND_RENAME(&TOCLONE#,"New_Element")

:SET &PARENT# = XML_SELECT_NODE(&XMLDocu#, "Child3")
:SET &RET# = XML_APPEND_ELEMENT(&PARENT#, &CLONECHILD#)

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

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

:ENDIF

:XML_CLOSE &XMLDOCU#

The following rows are then available in the activation log:

2013-08-14 13:32:27 – U0020408 Element: SubChild3
2013-08-14 13:32:27 – U0020408 Element: New_Element

 

See also:

Script element Description
XML_OPEN Opens an XML document for processing.
:XML_CLOSE Closes an XML document.