XmlCreateDocument Function

Action

Creates an empty XML document that can be populated with the other XML API functions like XmlCreateNode, XmlAppendChild, ... .

Include file

XmlAPI.bdh

Syntax

XmlCreateDocument( ): number;

Return value

  • document handle if successful

  • 0 otherwise

Example

dcltrans
  transaction TMain
  var
  hDocument, hRootNode, hChildNode, hResult : number;
  sAttrValue, sXmlString                    : string;
  begin
    hDocument  := XmlCreateDocument();
    hRootNode  := XmlCreateNode("root", XMLNODE_ELEMENT);
    hChildNode := XmlCreateNodeFromXml("<child1 attr1='avalue1'>childvalue1</child1>"
                                  "<child2 attr1='avalue2'>childvalue2</child2>");
    XmlAppendChild(hDocument, hRootNode);
    XmlAppendChild(hRootNode, hChildNode);
    hResult := XmlSelectSingleNode(hDocument, "/root/child2");
    XmlGetAttributeByName(hResult, "attr1", sAttrValue);
    XmlSetNodeAttribute(hResult, "attr1", "new avalue");
    XmlGetXml(hDocument, sXmlString);
  end TMain;