Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Jun 2005
    Posts
    44
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Question How to use ajax to get xml node value?

    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!

  • #2
    Senior Coder shyam's Avatar
    Join Date
    Jul 2005
    Posts
    1,563
    Thanks
    2
    Thanked 163 Times in 160 Posts
    Code:
    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);
      }
    }
    You never have to change anything you got up in the middle of the night to write. -- Saul Bellow

  • #3
    Regular Coder
    Join Date
    Nov 2007
    Location
    Leeds, UK
    Posts
    514
    Thanks
    24
    Thanked 19 Times in 19 Posts
    Quote Originally Posted by shyam View Post
    Code:
    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
    Working towards a Internet where we don't have website just browser applications Kill the Hyper-link and say hello to 3D Games in the browser :)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •