Problems with Xml, Javascript

A

arun32581

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="JavaScript" type="text/javascript">

function linksXML()
{
if (document.implementation && document.implementation.createDocument)
{
xmlDoc = document.implementation.createDocument("", "", null);
xmlDoc.onload = createTable;
}
else if (window.ActiveXObject)
{
xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.onreadystatechange = function () {if (xmlDoc.readyState == 4)
createTable()};
}
else
{
alert('Your browser can\'t handle this script');
return;
}
xmlDoc.load("google.xml");
}





function createTable()

{

var x = xmlDoc.getElementsByTagName('Websites');
var newEl = document.createElement('TABLE');
newEl.setAttribute('cellPadding',5);
var tmp = document.createElement('TBODY');
newEl.appendChild(tmp);
var row = document.createElement('TR');
for (j=0;j<x[0].childNodes.length;j++)
{
if (x[0].childNodes[j].nodeType != 1) continue;
var container = document.createElement('TH');
var theData = document.createTextNode(x[0].childNodes[j].nodeName);
container.appendChild(theData);
row.appendChild(container);
}
tmp.appendChild(row);
for (i=0;i<x.length;i++)
{
var row = document.createElement('TR');
for (j=0;j<x.childNodes.length;j++)
{
if (x.childNodes[j].nodeType != 1) continue;
var container = document.createElement('TD');
var theData =
document.createTextNode(x.childNodes[j].firstChild.nodeValue);
container.appendChild(theData);
row.appendChild(container);
}
tmp.appendChild(row);
}
document.getElementById('writeroot1').appendChild(newEl);

}


</script>
</head>
<body>

<a href="javascript:linksXML()">Test</a>

<p id="writeroot1" style="background-color: green;">
</p>

</body>
</html>
 
A

A. Bolmarcich

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

[snip pasted code]

If you want the URL elements in the XML to become hyperlinks instead of text in
the HTML, when creating the contents of each TD element replace

container.appendChild(theData);

with

if (x.childNodes[j].nodeName == 'URL') {
var theLink = document.createElement('A');
theLink.setAttribute('href', theData.data);
theLink.appendChild(theData);
container.appendChild(theLink);
} else {
container.appendChild(theData);
}
 
Joined
Sep 13, 2006
Messages
1
Reaction score
0
How to apply DIV 'JUSTIFY'

I am having problem applying the <DIV ALIGN='JUSTIFY'> for the below code.

var theLink = document.createElement('A');
theLink.setAttribute('href', theData.data);
theLink.appendChild(theData);
container.appendChild(theLink);
container.appendChild(document.createTextNode(': '));
container.appendChild(document.createTextNode(topicContent.data));
row.appendChild (container);
tmp.appendChild(row);

I want to apply 'JUSTIFY' on the result of the 'container' so that it looks good. How do I do that ? Please help.

Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,121
Latest member
LowellMcGu
Top