Can't get my XML to properly display in my HTML

Discussion in 'JavaScript' started by matthewst, Nov 9, 2006.

  1. #1
    I have two HTML doc's I'm working with. Neither one does exactly what I need them to do.

    What I need:
    My users will double click on a shortcut to an HTML page (can't use XSLT and I know this isn't the best way but I'm working with what I have available).

    That page will display information from an XML file.


    This HTML file will display everything but takes it out of the order it's in in the XML file. It displays all the timestamps then all the entries. It should be ts then enty then ts then entry and so on and so on.
    <html>
    <head>
    <script type="text/javascript" src="loadxmldoc.js"> 
    </script>
    </head>
    <body>
    
    <script type="text/javascript">
    xmlDoc=loadXMLDoc("CurrentLog.xml");
    
    var x=xmlDoc.getElementsByTagName('TStamp') 
    for (i=0;i<x.length;i++)
      {
      document.write(x[i].childNodes[0].nodeValue)
      document.write("<br />")
      }
    var x=xmlDoc.getElementsByTagName('Entry')
    for (n=0;n<x.length;n++)
      {
      document.write(x[n].childNodes[0].nodeValue)
      document.write("<br />")
      }
    </script>
    
    </body>
    </html>
    Code (markup):
    This HTML file keeps everything in order but only displays the first timestamp and entry:
    <html>
    <head>
    <script type="text/javascript">
    var xmlDoc
    function loadXML()
    {
    if (window.ActiveXObject)
      {
      xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
      xmlDoc.async=false;
      xmlDoc.load("CurrentLog.xml");
      getmessage()
      }
    }
    function getmessage()
    {
    document.getElementById("TStamp").innerHTML=
    xmlDoc.getElementsByTagName("TStamp")[0].firstChild.nodeValue
    document.getElementById("Entry").innerHTML=
    xmlDoc.getElementsByTagName("Entry")[0].firstChild.nodeValue
    }
    </script>
    </head>
    <body onload="loadXML()" bgcolor="#FFFFFF">
    <p><font size="7"><b>COBRA Log</b></font><p>
    <b>Time Stamp:</b><span id="TStamp"></span><br/>
    <b>Entry:</b><span id="Entry"></span>
    </p>
    </body>
    </html>
    Code (markup):
    Here is my CurrentLog.xml:
    <?xml version="1.0" standalone="yes"?>
    <IncrepDataset xmlns="http://tempuri.org/IncrepDataset.xsd">
      <Control>
        <Control_ID>0</Control_ID>
        <Name>DocViewer</Name>
        <Filename>docviewer.dll</Filename>
        <Icon>doc</Icon>
        <IncrepLoadable>true</IncrepLoadable>
        <Version>4.0.0.28546</Version>
        <TStamp>2006-11-06T18:00:09.4160070-06:00</TStamp>
      </Control>
      <Control>
        <Control_ID>-1</Control_ID>
        <Name>RIDS</Name>
        <Filename>ridswrapper.dll</Filename>
        <Icon>tool</Icon>
        <IncrepLoadable>true</IncrepLoadable>
        <Version>4.0.0.28559</Version>
        <TStamp>2006-11-06T18:00:32.8518090-06:00</TStamp>
      </Control>
      <IncidentLog>
        <IncidentLog_ID>-12</IncidentLog_ID>
        <TStamp>2006-11-06T18:01:26.8943678-06:00</TStamp>
        <Entry>-	'MAKE ALL NOTIFICATIONS.' checked</Entry>
        <AddedByUser>false</AddedByUser>
        <submission_id>0</submission_id>
        <Priority>Low</Priority>
        <Control_ID>-3</Control_ID>
      </IncidentLog>
      <IncidentLog>
        <IncidentLog_ID>-13</IncidentLog_ID>
        <TStamp>2006-11-06T18:01:26.9644749-06:00</TStamp>
        <Entry>-	'IDENTIFY ON-SCENE COMMAND (OSC)/ COMMAND POST (CP) LOCATION.' checked</Entry>
        <AddedByUser>false</AddedByUser>
        <submission_id>0</submission_id>
        <Priority>Low</Priority>
        <Control_ID>-3</Control_ID>
      </IncidentLog>
      <IncidentLog>
        <IncidentLog_ID>-14</IncidentLog_ID>
        <TStamp>2006-11-06T18:01:38.6222841-06:00</TStamp>
        <Entry>Incident Summary selected</Entry>
        <AddedByUser>false</AddedByUser>
        <submission_id>0</submission_id>
        <Priority>Low</Priority>
      </IncidentLog>
    </IncrepDataset>
    Code (markup):
    Here is my loadxmldoc.js:
    function loadXMLDoc(dname)
    {
    var xmlDoc;
    // code for IE
    if (window.ActiveXObject)
    {
    xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
    }
    // code for Mozilla, Firefox, Opera, etc.
    else if (document.implementation && document.implementation.createDocument)
    {
    xmlDoc=document.implementation.createDocument("","",null);
    }
    else
    {
    alert('Your browser cannot handle this script');
    }
    xmlDoc.async=false;
    xmlDoc.load(dname);
    return(xmlDoc);
    }
    Code (markup):
     
    matthewst, Nov 9, 2006 IP