...

View Full Version : How to use ajax to get xml node value?



EdwardKing
11-23-2008, 01:46 PM
I have a XML
<atag> <btag>rose </btag> <ctag> <dtag>doctor </dtag> <dtag>sale </dtag> </ctag> </atag>

use ajax to obtain the value of dtag:

var counts=this.xmlHttp.responseXML.getElementsByTagName("ctag");
for(var i=0;i <counts.length;i++){
//how ot get the value of dtag,such as show 'doctor' and 'sale'?

Thanks in advance!

shyam
11-23-2008, 04:17 PM
var counts=this.xmlHttp.responseXML.getElementsByTagName("ctag");
for(var i=0;i <counts.length;i++){
var dtags = counts[i].getElementsByTagName('dtag');
var dContent = [];
for ( j = 0; j < dtags.length; j++ ) {
dContent.push(dtags[i].firstChild.nodeValue);
}
}

barkermn01
12-03-2008, 06:17 PM
var counts=this.xmlHttp.responseXML.getElementsByTagName("ctag");
for(var i=0;i <counts.length;i++){
var dtags = counts[i].getElementsByTagName('dtag');
var dContent = [];
for ( j = 0; j < dtags.length; j++ ) {
dContent.push(dtags[i].firstChild.nodeValue);
}
}


Just to explain
the best way is to download the xml file this.xmlHttp.responseXML
Then treat it is a standad XML file getElementsByTagName("ctag")
Then the rest is to get the correct bit of that tag name out



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum