Skip to main content
Version: Next

DOM Append XML child node

DOM Append XML child node ( elementRef ; childType ; childValue ) -> Function result

ParameterTypeDescription
elementRefText🡒XML element reference
childTypeLongint🡒Type of child to append
childValueText, BLOB🡒Text or variable (Text or BLOB) whose value must be inserted as child node
Function resultText🡐Reference of child XML element

Description

The DOM Append XML child node command is used to append the childValue value to the XML node designated by elementRef.

The type of node created is specified by the childType parameter. In this parameter you can pass one of the following constants, located in the "XML" theme:

ConstantTypeValue
XML CDATALongint7
XML commentLongint2
XML DATALongint6
XML DOCTYPELongint10
XML ELEMENTLongint11
XML processing instructionLongint3

In childValue, pass the data to be inserted. You can pass a string or a 4D variable (string or BLOB). The contents of this parameter will always be converted into text.

Note: If the elementRef parameter designates the Document node (top level node), the command inserts a "Doctype" node before any other node. The same goes for processing instructions and comments, which are always inserted before the root node (but after the Doctype node).

Example 1

Adding a text type node:

 Reference:=DOM Create XML element(elementRef;"myElement")
 DOM SET XML ELEMENT VALUE(Reference;"Hello")
 temp:=DOM Create XML element(Reference;"br")
 temp:=DOM Append XML child node(Reference;XML DATA;"New")
 temp:=DOM Create XML element(Reference;"br")
 temp:=DOM Append XML child node(Reference;XML DATA;"York")

Result:

<myElement>Hello<br/>New<br/>York</myElement>

Example 2

Adding a processing instruction type node:

 $Txt_instruction:="xml-stylesheet type = \"text/xsl\" href=\"style.xsl\""
 Reference:=DOM Append XML child node(elementRef;XML Processing Instruction;$Txt_instruction)

Result (inserted before first element):

<?xml-stylesheet type="text/xsl" href="style.xsl"?>

Example 3

Adding a comment type node:

 Reference:=DOM Append XML child node(elementRef;XML Comment;"Hello world")

Result:

<!--Hello world-->

Example 4

Adding a CDATA type node:

 Reference:=DOM Append XML child node(elementRef;XML CDATA;"12 < 18")

Result:

<element><![CDATA[12 < 18]]></element>

Example 5

Adding or replacing a Doctype declaration type node:

 Reference:=DOM Append XML child node(elementRef;XML DOCTYPE;"Books SYSTEM \"Book.DTD\"")

Result (inserted before first element):

<!DOCTYPE Books SYSTEM  "Book.DTD">

Example 6

Adding or replacing an Element type node.

  • if the childValue parameter is an XML fragment, it is inserted as child nodes:
 Reference:=DOM Append XML child node(elementRef;XML ELEMENT;"simoneva")  

Result:

<parent>  
    <child>simon</child>
    <child>eva</child>
</parent>
  • otherwise, a new blank child element is appended:
 Reference:=DOM Append XML child node(elementRef;XML ELEMENT;"tbreak")  

Result:

<parent>  
    <tbreak/>
</parent>

If the contents of childValue are not valid, an error is returned.

See also

DOM GET XML CHILD NODES
DOM Get XML document ref