Default Namespaces in XML

XML namespaces can be used for more than defining namespace prefixes and using those prefixes with element names. You can also define default namespaces for elements using the xmlns attribute. To query elements with default namespaces you must call XmlSetNamespaces using a prefix name. The prefix name can later be used in an X-Path query.

See the following document:

  <child1 xmlns=’MyName1’>value1</child1>

To execute a query like /root/child1 you must define the namespace of child1 with XmlSetNamespaces using a self-defined prefix.

  transaction TMain
    hDoc, hChild : number;
    sValue, sXML : string;
    hDoc   := XmlCreateDocumentFromXml("<root><child1 xmlns=’MyName1’>value1<child></root>");
    XmlSetNamespaces(hDoc, "xmlns:myprefix='MyName1'");
    hChild := XmlSelectSingleNode("/root/myprefix:child");
  end TMain;