User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 392,009 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,236 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 1433 | Replies: 1
Reply
Join Date: Jul 2007
Posts: 1
Reputation: Sebarry is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Sebarry Sebarry is offline Offline
Newbie Poster

Parse an XML document with AJAX

  #1  
Jul 22nd, 2007
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
AddThis Social Bookmark Button
Reply With Quote  
Join Date: May 2006
Location: New Jersey
Posts: 1,422
Reputation: stymiee is on a distinguished road 
Rep Power: 5
Solved Threads: 34
Moderator
Staff Writer
stymiee's Avatar
stymiee stymiee is offline Offline
He's No Good To Me Dead

Re: Parse an XML document with AJAX

  #2  
Jul 22nd, 2007
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]);
}
John Conde
Brainyminds | Merchant Account Services | I Love Code
IT'S HERE: Merchant Accounts 101 Everything you need to know about merchant accounts!
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb JavaScript / DHTML / AJAX Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum

All times are GMT -4. The time now is 10:23 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC