View XML data in diferent browsers

admin

Administrator
Staff member
Greetings!!

I have a problem showing XML data and I need your help!...
At this moment I have a javascript function loadXML() in <head> for permit show data for example in IE and firefox:

<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("xml/destaques.xml");
getmessage()
}
// code for Mozilla, etc.
else if (document.implementation && document.implementation.createDocument)
{
xmlDoc= document.implementation.createDocument("","",null);
xmlDoc.load("xml/destaques.xml");
xmlDoc.onload=getmessage
}
else
{
alert('Your browser cannot handle this script');
}
}


function getmessage()
{
document.getElementById("dia").innerHTML = xmlDoc.getElementsByTagName("dia")[0].firstChild.nodeValue
document.getElementById("mes").innerHTML = xmlDoc.getElementsByTagName("mes")[0].firstChild.nodeValue
document.getElementById("ano").innerHTML = xmlDoc.getElementsByTagName("ano")[0].firstChild.nodeValue
document.getElementById("titulo").innerHTML = xmlDoc.getElementsByTagName("titulo")[0].firstChild.nodeValue
document.getElementById("amostra").innerHTML = xmlDoc.getElementsByTagName("amostra")[0].firstChild.nodeValue
document.getElementById("link").innerHTML = xmlDoc.getElementsByTagName("link")[0].firstChild.nodeValue
}


//-->
</script>
Load in <body onload="loadXML()">

and show in a table:

<table border="0">
<tr>
<td><img src=http://www.webdeveloper.com/forum/archive/index.php/"images/mark01.gif" width="10" height="9"></td>
<td class="txtDest02"><span id="dia"></span><span id="mes"></span><span id="ano"></span> - <span id="titulo"></span></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>
<p class="pBrd">
<span id="amostra"></span><a id="link">...Mais</a>
</p>
</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
</table>

...the problem is that it only show the first element destaque that have subelements like amostra, dia, etc and I want to show all. how can I do that??

Note: doing a data island with <xml> and the correspond techniques I can resolve the problem but the data doesn't apears in firefox...and I must use XML DOM
 
Back
Top