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
    Dec 2011
    Posts
    14
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Changing which xml files being loaded via button click

    is it possible that when you have your webpage open and loaded that when you click a button/image that the web page changes which xml file its loading?
    For example i have text being displayed via an xml file being loaded, is it possible to change which xml files being loaded?
    Change from data.xml to data2.xml..

  • #2
    Moderator
    Join Date
    May 2002
    Location
    Hayward, CA
    Posts
    1,459
    Thanks
    1
    Thanked 23 Times in 21 Posts
    How are you loading XML files in the first place? That'll get you more than halfway to your answer.
    "The first step to confirming there is a bug in someone else's work is confirming there are no bugs in your own."
    June 30, 2001
    author, Verbosio prototype XML Editor
    author, JavaScript Developer's Dictionary
    https://alexvincent.us/blog

  • #3
    New Coder
    Join Date
    Dec 2011
    Posts
    14
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Sorry, forgot to mention how i do it.
    This is the code that loads up a table of info from an xml file.

    <script>
    if (window.XMLHttpRequest)
    {// code for IE7+, Firefox, Chrome, Opera, Safari
    xmlhttp=new XMLHttpRequest();
    }
    else
    {// code for IE6, IE5
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.open("GET","datahtml.xml",false);
    xmlhttp.send();
    xmlDoc=xmlhttp.responseXML;

    document.write("<table border='15'>");
    var x=xmlDoc.getElementsByTagName("DJ");
    for (i=0;i<x.length;i++)
    {
    document.write("<tr><td>");
    document.write(x[i].getElementsByTagName("NAME")[0].childNodes[0].nodeValue);
    document.write("</td><td>");
    document.write(x[i].getElementsByTagName("AGE")[0].childNodes[0].nodeValue);
    document.write("</td><td>");
    document.write(x[i].getElementsByTagName("COUNTRY")[0].childNodes[0].nodeValue);
    document.write("</td><td>");
    document.write(x[i].getElementsByTagName("LABEL")[0].childNodes[0].nodeValue);
    document.write("</td></tr>");
    }
    document.write("</table>");
    </script>


  •  

    Posting Permissions

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