Hi,

I have a Javascript function that creates an Ajax request, returning an XML document into transport.responseXML . I want to process this document but without hardcoding each tag name i.e. xmlOptions[0].getElementsByTagName('salary')[0].firstChild.data . I would like to iterate over the XML document and find each tag and its value. The XML document I want to process is structured as such:

<job>
   <contactTelephone>028 ---------</contactTelephone>
   <contactName>Karen -------</contactName>
   <contactFax>028 -----------</contactFax>
   <contactEmail>karen@---------</contactEmail>
   <contactWebsite>www.---------</contactWebsite>
   </job>

Thanks,

Sean

Just loop through the array like you would any other array. See that zero? It can be a variable, too.

for (var i = 0; i <  xmlOptions[0].getElementsByTagName('salary').length; i++)
{
     document.write(xmlOptions[0].getElementsByTagName('salary')[i]);
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.