DOM Create XML Ref

4D - Documentation   Français   English   German   4th Dimension 2004, Command Theme List   4th Dimension 2004, Command Alphabetical List   4th Dimension 2004, Constant Theme List   Back   Previous   Next

version 2004


DOM Create XML Ref (root{; nameSpace}{; nameSpaceName; nameSpaceValue}{; nameSpaceName2; nameSpaceValue2; ...; nameSpaceNameN; nameSpaceValueN}) String

ParameterTypeDescription
rootStringName of root element
nameSpaceStringValue of namespace
nameSpaceNameStringNamespace name
nameSpaceValueStringNamespace value
Function resultStringRoot XML element reference

Description

The DOM Create XML Ref command creates an empty XML tree in memory and returns its reference.

Pass the name of the XML tree root element in the root parameter.

Pass the declaration of the namespace value of the tree in the optional nameSpace parameter (for example, "http://www.4d.com").

In this case, you must prefix the root parameter with the namespace name followed by : (for example, "MyNameSpace:MyRoot").

Note: The namespace is a string that allows you to make sure the XML variable names are unique. In general, a URL like http://www.mysite.com/myurl is used. The URL does not necessarily have to be valid, but it does have to be unique.

You can declare one or more additional namespaces in the generated XML tree using nameSpaceName/nameSpaceValue pairs. You can pass as many namespace name/value pairs as you want.

Important: Remember to call the DOM CLOSE XML command in order to free up the memory when you have finished using the XML tree.

Examples

1. Creating a single XML tree:

   C_STRING (16;vElemRef)
   vElemRef:=DOM Create XML Ref("MyRoot")

This code produces the following result:

<?xml version="1.0" encoding="UTF-8" standalone="no" ?> 
<MyRoot/>

2. Creating an XML tree with a single namespace:

   C_STRING (16;vElemRef)
   $Root:="MyNameSpace:MyRoot"
   $Namespace:="http://www.4D.com/tech/namespace"
   vElemRef:=DOM Create XML Ref($Root$Namespace)

This code produces the following result:

<MyNameSpace:MyRoot xmlns:MyNameSpace="http://www.4D.com/tech/namespace"/>

3. Creating an XML tree with several namespaces:

   C_STRING (16;vElemRef)
   C_STRING (80;$aNSName1;$aNSName2;$aNSValue1;$aNSValue2)
   $Root:="MyNameSpace:MyRoot"
   $Namespace:="http://www.4D.com/tech/namespace"
   $aNSName1:="NSName1"
   $aNSName2:= "NSName2"
   $aNSValue1:="http://www.4D.com/Prod/namespace"
   $aNSValue2:="http://www.4D.com/Mkt/namespace"
   vElemRef:=DOM Create XML Ref($Root;$Namespace;$aNSName1;$aNSValue1;$aNSName2;$aNSValue2)

This code produces the following result:

<MyNameSpace:MyRoot xmlns:MyNameSpace="http://www.4D.com/tech/nameSpace"
NSName1="http://www.4D.com/Prod/namespace"
NSName2="http://www.4D.com/Mkt/namespace"/>

See Also

DOM CLOSE XML, DOM SET XML OPTIONS.

System Variables or Sets

If the command was executed correctly, the system variable OK is set to 1. Otherwise, it is set to 0 and an error is generated.


4D - Documentation   Français   English   German   4th Dimension 2004, Command Theme List   4th Dimension 2004, Command Alphabetical List   4th Dimension 2004, Constant Theme List   Back   Previous   Next