XmlCreateNode Function

Action

If you do not specify a special node type, XmlCreateNode creates a new XML element node of specified name. The node can then be added as root node to a document or as child node to another XML element node. To set the value/attributes of the node use XmlSetNodeValue, XmlSetNodeAttribute.

To create a different type (e.g.: COMMENT, CDATA, ...) of XML node, pass the desired type as 2nd parameter. The name parameter will be ignored for other types than the element or attribute type.

Include file

XmlAPI.bdh

Syntax

XmlCreateNode( in sNodeName  : string,
               in nNodeType  : number optional,
               in sNamespace : string optional ): number;

Return value

  • node handle if successful

  • 0 otherwise

Parameter Description
sNodeName Name of the node that will be created
nNodeType

(optional) Type of the node that should be created. If omitted an XML element will be created: Possible types:

  • XMLNODE_ELEMENT

  • XMLNODE_ATTRIBUTE

  • XMLNODE_TEXT

  • XMLNODE_CDATA_SECTION

  • XMLNODE_ENTITY_REFERENCE

  • XMLNODE_ENTITY

  • XMLNODE_PROCESSING_INSTRUCTION

  • XMLNODE_COMMENT

  • XMLNODE_DOCUMENT_FRAGMENT

sNamespace

(optional)

String defining the namespace Uniform Resource Identifier (URI).

If specified, the node is created in the context of the namespaceURI with the prefix specified on the node name. If the sNodeName parameter does not have a prefix, this is treated as the default namespace.

Example

dcltrans
  transaction TMain 
  var
    hDocument, hResult, hNewNode : number;
  begin
    hDocument := XmlCreateDocumentFromXml( "<root><child1 attr1='avalue1'>childvalue1</child1>"
                 "<child2 attr1= 'avalue2'>childvalue2</child2></root>");
    hNewNode := XmlCreateNode("child3");
    hResult := XmlSelectSingleNode(hDocument, "/root"):
    XmlAppendChild(hResult, hNewNode);
  end TMain;