Xml

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • newgirllondon
    New Member
    • Jan 2014
    • 1

    Xml

    I am new and working with XML.

    I have a number of xml files exist on the server, i want the html web page must provide me with the means to choose a single xml file and subsequently display this as a table on the same web page. A drop-down list box is to be used to present the list of available xml files to me. The drop-down list box contents must reflect the files presently available in the specific xml folder on the server
    .

    drop-down list box and table must be populated as ecessary using Ajax techniques.

    so far i work out a basic code to display xml to html as a table, need direction or some help.

    Code:
    <!DOCTYPE html>
    <html>
    <head>
    	<meta charset="utf-8">
    	<title>XML to HTML</title>
    </head>
    
    <body>
    <br />
    <br />
    
    <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","books.xml",false);
    xmlhttp.send();
    xmlDoc=xmlhttp.responseXML; 
    
    document.write("<table border='2'>");
    var x=xmlDoc.getElementsByTagName("book");
    for (i=0;i<x.length;i++)
      { 
      document.write("<tr><td>");
      document.write(x[i].getElementsByTagName("author")[0].childNodes[0]. nodeValue);
      document.write("</td><td>");
      document.write(x[i].getElementsByTagName("last")[0].childNodes[0].nodeValue);
      document.write("</td><td>");
      document.write(x[i].getElementsByTagName("title")[0].childNodes[0].nodeValue);
      document.write("</td><td>");
      document.write(x[i].getElementsByTagName("genre")[0].childNodes[0].nodeValue);
      document.write("</td><td>");
      document.write(x[i].getElementsByTagName("price")[0].childNodes[0].nodeValue);
      document.write("</td><td>");
      document.write(x[i].getElementsByTagName("publish_date")[0].childNodes[0].nodeValue);
      document.write("</td><td>");
      document.write(x[i].getElementsByTagName("description")[0].childNodes[0].nodeValue);
      document.write("</td></tr>");
      }
    document.write("</table>");
    
    </script>
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    scrap document.write( ). it will make things complicated soon enough.

    drop-down list box and table must be populated as ecessary using Ajax techniques.
    do you have any means to get the file names?

    Comment

    • Nepomuk
      Recognized Expert Specialist
      • Aug 2007
      • 3111

      #3
      Hi newgirllondon and welcome to bytes.com!

      At first glance at least the code you've written so far looks good. You say that you need direction or help; what with? Does the code work as intended? Have you tried including it into the context it is intended for? What are you stuck with?

      Comment

      Working...