Once the XML data is loaded into an XML DOM object or an XML DSO, the objects can be used to traverse through the data in the data nodes of the XML document. The data nodes need to be traversed before it can be prepped for presentation.  Then the data can be placed into HTML.

XML DOM Object

Each XML document and each XML DOM Document object consists of a single root element and its descendants (other elements). If it is an XHTML document, then the root element must be <html>. An XML DOM object is traversed primarily by accessing its root element.

'The root element or node.

The childNodes collection of the root element has all the usual characteristics of 0-based collections. EGs:

'The child node.
'The value in the child node.
'The number of child nodes.
'The grandchild node.

Note that an object variable can be set to any node. EGs:

nodeRoot = XMLDOMObject.documentElement
nodeChild = NodeRootchildNodes.item(n)
nodeGrandChild = NodeChild.childNodes.item(n)

You can navigate to any mode in this fashion. A child node of a node can also be accessed by its tag name. This gets the value of the first node with that tag name if it exists, but note that there may be multiple child nodes with that tag name.

ValueOfChildOfAnyNode = nodeAny.getElementsByTagName('tagName').item(n).text

Once the value of a particular is node is captured and set to some variable, it can be placed into HTML or used in additional scripting.

Prep for HTML

Assume that we've captured a value:

<script ....>
strValue = XMLDOMObject.documentElement.childNodes.item(n).text

That value may be placed anywhere in the HTML body with this bit of script:


Here are bits of script that cycles through an XML DOM object that is structured like a typical table (see XDM DSO below).

This one basically goes through the items by their indexes and then looks for field/data node names.

rstNodeRoot = XMLDOMObject.documentElement;
for (rstCount = 0; rstCount < rstNodeRoot.length; rstCount++){
  recNodeChild = rstNodeRoot.item(rstCount).childNodes;
  for (fldCount = 0; fldCount < recNodeChild.length; fldCount++){
    switch (recNodeChild.item(fldCount).tagName){
      case "FieldName1";
        strFieldValue1 = recNodeChild.item(fldCount).text;
      case "FieldValue2";
        strField2 = recNodeChild.item(fldCount).text;
      case "FieldValueN";
        strFieldN = recNodeChild.item(fldCount).text;
  document.writeln("<li>" + strFieldValue1 + "</li>");
  document.writeln("<li>" + strFieldValue2 + "</li>");
  document.writeln("<li>" + strFieldValueN + "</li>");

Prep for DHTML

Some event can call this function:

<script ...>
function CallMe(){
  span1.innerText = XMLDOMObject.documentElement.childNodes.item(n).text

That function will place the value into this span which could be anywhere in the body:

<span id="span1"></span>


XML DSO can be navigated like an XML DOM object but then why bother to make an XML DSO?

XML DSOs (Data Source Objects) can be used like an XML DOM object but it also has two major advantages:

However, the XML DSO also has two major drawbacks:

Here is an example of XML data structured like a typical table/recordset that has 2 records/rows and 3 fields/columns:


A node, i.e. a row can be made the current code with script similar to either of the following:

recCurrent = XMLDSO.XMLDocument.documentElement.childNodes.item(n)
recCurrent = XMLDSO.documentElement.childNodes.item(n)

Script can get the grandchild node value, i.e. the value of a field in the current row with this syntax:

fldValue = recCurrent.childNodes.item(n).text
fldValue = XMLDSO.recordset("FieldName")

The rows can be navigated by calling upon script similar to the following:

function FMovePrevious(){
  if (XMLDSO.recordset.bof){
    alert("Already at BOF");
    if (XMLDSO.recordset.bof){
      alert("This is the first row");

Binding HTML to the XML DSO

HTML elements to be bound to the XML DSO.

This example shows the value of the specified field for the current row.

<span datasrc="#XMLDSO" datafld="FieldName"></span>

This example will show an image if the value of the specified field contains the path and file name of an image.

<src  datasrc="#XMLDSO" datafld="FieldName">

An HTML table can be bound to the XML DSO and display all of its data. All rows that are not part of a <thead> or <tfoot> row group are repeated once for each field/child node.

<table datasrc="#XMLDSO">
    <td><span datafld="FieldName1"></span></td>
    <td><span datafld="FieldName2"></span></td>
    <td><span datafld="FieldNameN"></span></td>
    <td colspan="n"><hr/></td>

Page Modified: (Hand noted: ) (Auto noted: )