DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: XML was loading via Javscript into table, now is not

  1. #1
    Join Date
    Feb 2010
    Posts
    1

    XML was loading via Javscript into table, now is not

    XML data was displaying via Javascript on page, now is not
    A page displaying items from a database was reading data in and displaying it properly in a table, and apparently stopped doing so when I changed the xml tags in the xml file. But this continued when I changed them in the Javascript script. The HTML loads and displays properly, including the table header.

    The HTML page is http://www.quantumboatworks.cxr.cc/demo/forsale.php. (The relevant script is shown below.)

    TheXML page is http://www.quantumboatworks.cxr.cc/d...ms/catalog.xml. (The text of the file is shown at the bottom of this post.)

    I built this off of a W3 schools tutorial at http://www.w3schools.com/xml/xml_applications.asp (this page displays the code of the XML data) and its application editor at http://www.w3schools.com/xml/tryit.a..._display_table.

    Here is the relevant Javascript:

    </thead>

    <script type="text/javascript">

    if (window.XMLHttpRequest)
    {
    xhttp=new XMLHttpRequest();
    }
    else // Internet Explorer 5/6
    {
    xhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }

    xhttp.open("GET","saleitems/catalog.xml");
    xhttp.send("");
    xmlDoc=xhttp.responseXML;
    document.write(xmlDoc);
    try {

    j=1;
    document.write("");
    var x=xmlDoc.getElementsByTagName("saleitem");
    } else {
    document.write("\n",err.exception,"\n");
    }
    alert(x.length);
    for (i=0;i<x.length;i++)
    {
    //alternate row colors
    if (j==0) {
    rowClass = "main";
    j = 1;
    } else {
    rowClass = "alt";
    j = 0;
    }
    document.write("<tr class='",rowClass,"'><td>");

    document.write("<b>");
    document.write(x[i].getElementsByTagName("itemtype")[0].childNodes[0].nodeValue);
    document.write("</b>");

    document.write("</td><td>");
    document.write(x[i].getElementsByTagName("itemname")[0].childNodes[0].nodeValue);
    document.write("</td><td>");
    document.write(x[i].getElementsByTagName("brand")[0].childNodes[0].nodeValue);
    document.write("</td><td>");
    document.write(x[i].getElementsByTagName("model")[0].childNodes[0].nodeValue);
    document.write("</td><td>");
    document.write(x[i].getElementsByTagName("year")[0].childNodes[0].nodeValue);
    document.write("</td><td>");
    document.write(x[i].getElementsByTagName("length")[0].childNodes[0].nodeValue);
    document.write("</td><td>");
    document.write(x[i].getElementsByTagName("width")[0].childNodes[0].nodeValue);
    document.write("</td><td>");
    document.write(x[i].getElementsByTagName("height")[0].childNodes[0].nodeValue);
    document.write("</td><td>");
    document.write(x[i].getElementsByTagName("weight")[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("description")[0].childNodes[0].nodeValue);
    document.write("</td><td>");

    document.write('<img src="images/');
    document.write(x[i].getElementsByTagName("picture")[0].childNodes[0].nodeValue);
    document.write('" />');
    alert(i+"..."+x[i].getElementsByTagName("itemtype")[0].childNodes[0].nodeValue+"..."+x[i].getElementsByTagName("picture")[0].childNodes[0].nodeValue);

    document.write("</td></tr>");
    }
    </script>
    </table>

    Here is the text of the XML file. The data was displaying properly even without a css stylesheet, which the tutorial example does not seem torely on in any way shown.

    <?xml version="1.0" encoding="ISO-8859-1"?>
    <?xml-stylesheet type="text/css" href=""?>
    <catalog>
    <saleitem>
    <itemid>1</itemid>
    <itemtype>Tugboat</itemtype>
    <itemname>Valiant</itemname>
    <brand>Columbia Tugboat Company</brand>
    <model>Warpspeed</model>
    <year>1950</year>
    <length>95 ft</length>
    <width>na</width>
    <height>na</height>
    <weight>na</weight>
    <price>40,000.00</price>
    <description>This 95 foot long tugboat has two stories on deck, and it RUNS FAR, RUNS FAST.</description>
    <picture>sometugboat.jpg</picture>
    <employee>na</employee>
    <datestamp>na</datestamp>
    </saleitem>
    <saleitem>
    <itemid>2</itemid>
    <itemtype>Entertainment Center</itemtype>
    <itemname>na</itemname>
    <brand>Downtown Home Furnishings</brand>
    <model>na</model>
    <year>1985</year>
    <length>na</length>
    <width>na</width>
    <height>na</height>
    <weight>na</weight>
    <price>5.00</price>
    <description>This entertainment center was given to us by someone who moved to Virginia and could not take it with them.</description>
    <picture>someentertainmentcenter.jpg</picture>
    <employee>na</employee>
    <datestamp>na</datestamp>
    </saleitem>
    <saleitem>
    <itemid>3</itemid>
    <itemtype>Television</itemtype>
    <itemname>na</itemname>
    <brand>Sony</brand>
    <model>W569-A</model>
    <year>1996</year>
    <length>na</length>
    <width> </width>
    <height>na</height>
    <weight>na</weight>
    <price>10.00</price>
    <description>This television has a 19 inch screen and has medium resolution but is otherwise reliable.</description>
    <picture>sometelevision.jpg</picture>
    <employee>na</employee>
    <datestamp>na</datestamp>
    </saleitem>
    <saleitem>
    <itemid>4</itemid>
    <itemtype>VCR</itemtype>
    <itemname>na</itemname>
    <brand>Zenix</brand>
    <model>YF812-F34</model>
    <year>1999</year>
    <length>na</length>
    <width>na</width>
    <height>na</height>
    <weight>na</weight>
    <price>5.00</price>
    <description>This 4-head VCR has channel skipping capability.</description>
    <picture>someVCR.jpg</picture>
    <employee>na</employee>
    <datestamp>na</datestamp>
    </saleitem>
    <saleitem>
    <itemid>5</itemid>
    <itemtype>Desk</itemtype>
    <itemname>na</itemname>
    <brand>na</brand>
    <model>na</model>
    <year>na</year>
    <length>na</length>
    <width>na</width>
    <height>na</height>
    <weight>na</weight>
    <price>10.00</price>
    <description>This 6-drawer wooden desk has a few scratches but the drawers have been restored to smooth function.</description>
    <picture>someWooden_desk.jpg</picture>
    <employee>na</employee>
    <datestamp>na</datestamp>
    </saleitem>
    </catalog>

  2. #2
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,663
    What changed in your environment that could have triggered this?

Similar Threads

  1. Replies: 0
    Last Post: 05-21-2007, 02:17 AM
  2. Reading XML into a table
    By BrendonMelville in forum XML
    Replies: 0
    Last Post: 02-06-2006, 10:03 AM
  3. Covert SQL Table into XML
    By suras in forum XML
    Replies: 0
    Last Post: 05-10-2005, 03:26 AM
  4. query tuning
    By dhaya in forum Database
    Replies: 11
    Last Post: 08-25-2003, 05:24 PM
  5. Loading XML file from within a project
    By T O'Pry in forum .NET
    Replies: 9
    Last Post: 09-10-2002, 02:23 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center