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. |
Name |
New name of the duplicated element |
Return code |
---|
Reference to the new, duplicated element. |
The script element duplicates an element of the XML document that is open, and renames the duplicated element. All subordinate elements and values are taken into consideration during duplication.
Important!
- You must append the duplicated element to an element. For more information, see XML_APPEND_ELEMENT.
- Spaces are not permitted in the element name, and lead to a runtime error.
Notes:
- The XML structure will only be modified in the memory. The script element does not have an effect on the Documentation tab.
- Use the XML_OPEN script function to open the XML document. For more information, see XML_OPEN.
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: