Browsing the XML Document

The handle to a document is the handle to a "virtual" root node. The root node of an XML document would be the first child of the document handle. Typically, an XML document only has one root element - so you would always get the root node by getting the first child of the document. But if the root contains processing instructions (<?xml ... >), these instructions are also children of the document.

Starting at the "virtual" document root node, you can iterate through all nodes in a document. You can get the child nodes of a node with XmlGetChildNodes. This function returns a handle to a node list. A node list contains 0 or more node handles. These handles can be received with XmlGetItem with a 0 based index to the element in the list. The number of elements can be received with XmlGetCount on the node list. You can access a child node directly with XmlGetChildByIndex.

transaction TMain
  hDoc, hChildren, hRoot, hChild : number;
  hDoc      := XmlCreateDocumentFromXml("<root><child>value1</child><child>value2</child></root>");
  hRoot     := XmlGetChildByIndex(hDoc, 0);
  hChildren := XmlGetChildNodes(hRoot);
  hChild    := XmlGetItem(hChildren, 1);
end TMain;