I am developing a page for Mozilla/IE which reads xml data and when the
link on the page is clicked it displays the data as a table.
The display is controlled by a Javascript. Everything works fine. But
in the table one of the sections is a URL. I want this to be clickable
so that it takes me to the corresponding webpage. I am new to this and
tried hard to fix this but cudnt find my way around. I tried adding an
xsl sheet but still it doesnt seem to fix the problem.
Could anyone help me out. I have pasted the code below
Thanks a lot
***XML*****
<?xml version="1.0" encoding="ISO-8859-1"?>
<logs>
<Websites>
<title>Google </title>
<country>US</country>
<URL>http://www.google.com</URL>
</Websites>
<Websites>
<title>CNN</title>
<country>US</country>
<URL>http://www.cnn.com</URL>
</Websites>
</logs>
***HTML*******
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<script language="JavaS cript" type="text/javascript">
function linksXML()
{
if (document.imple mentation && document.implem entation.create Document)
{
xmlDoc = document.implem entation.create Document("", "", null);
xmlDoc.onload = createTable;
}
else if (window.ActiveX Object)
{
xmlDoc = new ActiveXObject(" Microsoft.XMLDO M");
xmlDoc.onreadys tatechange = function () {if (xmlDoc.readySt ate == 4)
createTable()};
}
else
{
alert('Your browser can\'t handle this script');
return;
}
xmlDoc.load("go ogle.xml");
}
function createTable()
{
var x = xmlDoc.getEleme ntsByTagName('W ebsites');
var newEl = document.create Element('TABLE' );
newEl.setAttrib ute('cellPaddin g',5);
var tmp = document.create Element('TBODY' );
newEl.appendChi ld(tmp);
var row = document.create Element('TR');
for (j=0;j<x[0].childNodes.len gth;j++)
{
if (x[0].childNodes[j].nodeType != 1) continue;
var container = document.create Element('TH');
var theData = document.create TextNode(x[0].childNodes[j].nodeName);
container.appen dChild(theData) ;
row.appendChild (container);
}
tmp.appendChild (row);
for (i=0;i<x.length ;i++)
{
var row = document.create Element('TR');
for (j=0;j<x[i].childNodes.len gth;j++)
{
if (x[i].childNodes[j].nodeType != 1) continue;
var container = document.create Element('TD');
var theData =
document.create TextNode(x[i].childNodes[j].firstChild.nod eValue);
container.appen dChild(theData) ;
row.appendChild (container);
}
tmp.appendChild (row);
}
document.getEle mentById('write root1').appendC hild(newEl);
}
</script>
</head>
<body>
<a href="javascrip t:linksXML()">T est</a>
<p id="writeroot1 " style="backgrou nd-color: green;">
</p>
</body>
</html>