Click to See Complete Forum and Search --> : Problem embedding XML in my HTML


matthewst
11-07-2006, 06:35 AM
I can get the example at Http://www.w3schools.com/xml/xml_data_island.asp to work just fine but when I try it with my own XML and HTML files it only displays a little white box.

My 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>
- <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>

My HTML:<html>
<body>

<xml id="log" src="CurrentLog.xml"></xml>

<table border="1" datasrc="#log">
<tr>
<td><span datafld="AddedByUser"></span></td>
<td><span datafld="Priority"></span></td>
</tr>
</table>

</body>
</html>

Charles
11-07-2006, 07:00 AM
You can't mix XML and HTML, that's what XHTML is for.

matthewst
11-07-2006, 07:06 AM
I just need a simple way to pull data from my XML file.
If anyone has any ideas I'd love to try'em.

Charles
11-07-2006, 07:16 AM
Embed the XML in a XHTML document but save the document with a ".xml" file extension. Then provide an XSLT stylesheet describing how to transform the document to HTML.

It's quite simple, really.

matthewst
11-07-2006, 07:26 AM
I've never heard of an XSLT. I just know that w3schools was able to pull data from their XML file and I can't, but I don't see why.

Charles
11-07-2006, 08:35 AM
Even if you do get it to work it will only work in some versions of MSIE. See instead: http://www.w3schools.com/xml/xml_xsl.asp .

matthewst
11-07-2006, 09:35 AM
This is for an internal website. IE is the only authorized web browser.

matthewst
11-08-2006, 06:38 AM
I know using data islands isn't the cool hip way to do things but it's the only way I understand. Can anyone tell me why my HTML won't pull data from my XML?

Charles
11-08-2006, 06:48 AM
[I]t's the only way I understand.Your current situation would seem to prove that false.

What exactly are you up to?

matthewst
11-08-2006, 06:58 AM
You got me there!!

Short story:
The brass wants to be able to view the XML log in a webpage, but they only want to see data relevent to them.

Long story:
The base I work at (Tinker AFB) uses a program called WOLF to estimate blast radius and varius other stuff. WOLF keeps a log of every keystroke, window opened, and button clicked while running. The brass needs to review this log after each exercise. Unfortunately WOLF saves the log in XML only. Since they don't want to read through all the tags and "what not" it's up to me to pull out all the relevent data and present it to them in a more "user friendly" manner.

Charles
11-08-2006, 07:49 AM
XSLT is very much the way to go.

And if this is for the US Government you've got to watch out for the 503 accessibility rules. Don't rely on JavaScript and don't make anything that depends upon MSIE.

matthewst
11-08-2006, 09:40 AM
I was able to get this to work, sort of.
<html>
<head>
<script type="text/javascript">
var xmlDoc
function loadXML()
{
//load xml file
// code for IE
if (window.ActiveXObject)
{
xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async=false;
xmlDoc.load("CurrentLog.xml");
getmessage()
}
// code for Mozilla, etc.
else if (document.implementation &&
document.implementation.createDocument)
{
xmlDoc= document.implementation.createDocument("","",null);
xmlDoc.load("CurrentLog.xml");
xmlDoc.onload=getmessage
}
else
{
alert('Your browser cannot handle this script');
}
}function getmessage()
{
document.getElementById("IncidentLog_ID").innerHTML=
xmlDoc.getElementsByTagName("IncidentLog_ID")[0].firstChild.nodeValue
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>Log ID:</b><span id="IncidentLog_ID"></span><br/>
<b>Time Stamp:</b><span id="TStamp"></span><br/>
<b>Entry:</b><span id="Entry"></span>
</p>
</body>
</html>

The problem is I can't get it to read beyond the first IncidentLog_ID, TStamp, and Entry. There are hundreds of ID's, TStamps, and Entrys in one of the real logs. How do I make the HTML read all of them?

matthewst
11-08-2006, 09:44 AM
HA!! Just read your post!
I got a special pass to do whatever needs to be done. "Just make it work" were the exact words spoken to me.

matthewst
11-13-2006, 09:07 AM
This is what I need:

User opens HTML file---->data from XML file is displayed in order in HTML file

This is my problem:

User opens HTML file----> Only the heading "current log" and "tstamp" and "entry" are displayed

I took the HTML and SXL from http://www.w3schools.com/xsl/xsl_client.asp

HTML:
<html>
<body>
<script type="text/javascript">// Load XML
var xml = new ActiveXObject("Microsoft.XMLDOM")
xml.async = false
xml.load("CurrentLog.xml")// Load XSL
var xsl = new ActiveXObject("Microsoft.XMLDOM")
xsl.async = false
xsl.load("CurrentLog.xsl")// Transform
document.write(xml.transformNode(xsl))
</script>
</body>
</html>

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>
- <Control>
<Control_ID>-2</Control_ID>
<Name>Explosives</Name>
<Filename>atfwrapper.dll</Filename>
<Icon>tool_bomb</Icon>
<IncrepLoadable>true</IncrepLoadable>
<Version>4.0.0.28559</Version>
<TStamp>2006-11-06T18:01:01.2952610-06:00</TStamp>
</Control>
- <Control>
<Control_ID>-3</Control_ID>
<Name>ChecklistViewer.Bomb Response</Name>
<Filename>checklistwrapper.dll</Filename>
<Icon>tool_checklist</Icon>
<IncrepLoadable>false</IncrepLoadable>
<Version>4.0.0.28559</Version>
<TStamp>2006-11-06T18:01:21.5461976-06:00</TStamp>
</Control>
- <DataType>
<Datatype_id>1</Datatype_id>
<name>String</name>
<description />
</DataType>
- <IncidentLog>
<IncidentLog_ID>-10</IncidentLog_ID>
<TStamp>2006-11-06T18:01:26.7541536-06:00</TStamp>
<Entry>- 'COMMENCE IED SOP/ERG ACTIONS. GATHER ALL INFO.' checked</Entry>
<AddedByUser>false</AddedByUser>
<submission_id>0</submission_id>
<Priority>Low</Priority>
<Control_ID>-3</Control_ID>
</IncidentLog>
- <IncidentLog>
<IncidentLog_ID>-11</IncidentLog_ID>
<TStamp>2006-11-06T18:01:26.8142454-06:00</TStamp>
<Entry>- 'SET INITIAL EXCLUSION AREA.' checked</Entry>
<AddedByUser>false</AddedByUser>
<submission_id>0</submission_id>
<Priority>Low</Priority>
<Control_ID>-3</Control_ID>
</IncidentLog>
- <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>

XSL:
<?xml version="1.0" encoding="ISO-8859-1"?>
<!-- Edited with XML Spy v2006 (http://www.altova.com) -->
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method='html' version='1.0' encoding='UTF-8' indent='yes'/>

<xsl:template match="/">
<html>
<body>
<h2>Current Log</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th align="left">TStamp</th>
<th align="left">Entry</th>
</tr>
<xsl:for-each select="tstamp/entry">
<tr>
<td><xsl:value-of select="TStamp"/></td>
<td><xsl:value-of select="Entry"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

I have two other versions of the HTML file that don't require XSL but they only half work.
One displays everything I want but not in the right order the other displays in the right order
but only displays the first TStamp and Entry.