Skip to main content
Version: 20 R7 BETA

DOM Append XML child node

DOM Append XML child node ( elementRef ; childType ; childValue ) : Text

ParameterTypeDescription
elementRefTextXML element reference
childTypeIntegerType of child to append
childValueText, BlobText or variable (Text or BLOB) whose value must be inserted as child node
Function resultTextReference 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 CDATAInteger7
XML commentInteger2
XML DATAInteger6
XML DOCTYPEInteger10
XML ELEMENTInteger11
XML processing instructionInteger3

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