From: www.itworld.com

Parsing an XML Document the Easy Way

by David Wall

March 26, 2002 —

 

Once you've read an XML document into memory, like this...

var xmlDocHolder = new ActiveXObject("MSXML2.DOMDocument")
xmlDocHolder.load("http://www.davidwall.com\countryList.xml")

...you can begin to read elements of that document. The document
countrylist.xml contains, in part, this structure:



United States of America


Japan

To refer to data, we refer to a nested series of arrays. The element
containing the data "Japan" would be referred to like this:

JapanNode = xmlDocHolder.childNodes[0].childNodes[1].childNodes[0]

That is, we want to refer to the first (0) element (officialName) of
the second (1) element (country) of the first (0) element
(countryList). The word "Japan" itself -- the data -- would be
referenced as:

JapanText = xmlDocHolder.childNodes[0].childNodes[1].childNodes[0].text