4D v13.4

DOM Append XML child node

Home

 
4D v13.4
DOM Append XML child node

DOM Append XML child node 


 

DOM Append XML child node ( elementRef ; childType ; childValue ) -> Function result 
Parameter Type   Description
elementRef  Text in XML element reference
childType  Longint in Type of child to append
childValue  Text, BLOB in Text or variable (Text or BLOB) whose value must be inserted as child node
Function result  Text in Reference of child XML element

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:

Constant Type Value
XML CDATA Longint 7
XML Comment Longint 2
XML DATA Longint 6
XML DOCTYPE Longint 10
XML ELEMENT Longint 11
XML Processing Instruction Longint 3

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).

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>

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"?>

Adding a comment type node:

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

Result:

<!--Hello world-->

Adding a CDATA type node:

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

Result:

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

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">

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;"<child>simon</child><child>eva</child>")

    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.

 
PROPERTIES 

Product: 4D
Theme: XML DOM
Number: 1080

 
INDEX

Alphabetical list of commands

 
HISTORY 

Created: 4D v12

 
SEE ALSO 

DOM GET XML CHILD NODES
DOM Get XML document ref