XML_CLONE_AND_RENAME

Use the XML_CLONE_AND_RENAME script function to duplicate an XML document's open element and rename the duplicated element. All subordinate elements and values are considered during duplication.

Important!

  • The XML structure is modified in the memory only. You do not see the changes of XML_CLONE_AND_RENAME on the structured documentation page.
  • You must append the duplicated element to an element. For more information, see XML_APPEND_ELEMENT.
  • Do not use spaces or blanks in the element name. They cause a runtime error.

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

Syntax

XML_CLONE_AND_RENAME(Element, Name)

Script Function and Parameters

  • XML_CLONE_AND_RENAME
    Duplicates and renames an XML element

  • 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

This script function returns the reference to the new duplicated element.

Example

The following example opens the @Details structured documentation page of the own object. The 'Sub-Child-A' element located in the 'Child1' parent element is duplicated with the name 'New_Element'. The new element and the sub-elements of 'Child3' are written to the activation report.

Screenshot showing a Strucuted Documentation page that includes the elements Child1 with the sub-elements Sub-Child-A and Sub-Child-B, Child2 with the Sub-Child-C, and Child3 with the Sub-Child_D

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

:IF &XMLDOCU# <>
""
:SET &TOCLONE# = XML_SELECT_NODE(&XMLDOCU#,"Child2/Sub-Child-A")

: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 activation report shows the following lines

Screenshot of a report showing the Sub_Child_D as the sub-element of Child3, and the new element called New_Element

See also: