XmlSetNamespaces Function

Action

Sets the namespaces and the prefix for the namespaces that will be recognized by the XML parser.

If no namespace is defined, the parser will recognize all namespaces that are defined in the root node with the prefixes that are defined in the document.

The namespace definition string has to be defined with xmlns:PREFIX= 'URI'. Multiple namespaces can be defined in the string - seperated by blank.

Example: xmlns:NS1='http://testns1.org' xmlns:NS2='http://testns2.org'

Include file

XmlAPI.bdh

Syntax

XmlSetNamespaces( in hDoc        : number,
                  in sNamespaces : string ): boolean;

Return value

  • true if successful

  • false otherwise

Parameter Description
hDoc Handle to an XML document
sNamespaces

Namespaces definition string

Default the parser will recognize all namespaces that are defined in the root node with the prefixes that are defined in the document.

Example

dcltrans
  transaction TMain
  var
    hDocument, hResult : number;
  begin
    hDocument := XmlCreateDocumentFromXml( "<ns1:root xmlns:ns1='http://test.org' ><child1 attr1='avalue1'>childvalue1</child1>"
                 "<child2 attr1= 'avalue2'>childvalue2</child2></ns1:root>");
    XmlSetNamespaces(hDocument, "xmlns:ns1='http://test.org'nxmlns:ns2='http://test2.org'");
    hResult := XmlSelectSingleNode(hDocument, "/ns1:root/child2");
    XmlSetNodeAttribute(hResult, "attr1", "newavalue1");
  end TMain;