Search for:
Jump to: 
Your Ad Here
Post new topic Reply to topic
Author Message
 Post subject: Converting xml file to html using javascript
PostPosted: Fri Jun 06, 2008 7:05 am 
Offline

Joined: Mon Nov 12, 2007 10:12 am
Posts: 355
Hi, here i have the code to convert the latesttopics.xml to latesttopics.html file to html using javascript
<script type="text/javascript">
var xDoc;

// verify that browser supports XML features and load external .xml file
function verifySupport(xFile) {
if (document.implementation && document.implementation.createDocument) {
// this is the W3C DOM way, supported so far only in NN6+
xDoc = document.implementation.createDocument("", "theXdoc", null);
} else if (typeof ActiveXObject != "undefined") {
// make sure real object is supported (sorry, IE5/Mac)
if (document.getElementById("msxml").async) {
xDoc = new ActiveXObject("Msxml.DOMDocument");
}
}
if (xDoc && typeof xDoc.load != "undefined") {
// load external file (from same domain)
xDoc.load(xFile);
return true;
} else {
var reply = confirm("This example requires a browser with XML support, " +
"such as IE5+/Windows or Netscape 6+.\n \nGo back to previous page?");
if (reply) {
history.back();
}
}
return false;
}

// Draw table from xDoc document tree data
function drawTable(tbody) {
var tr, td, i, j, oneRecord;
tbody = document.getElementById(tbody);
// node tree
var data = xDoc.getElementsByTagName("LatestTopics")[0];
// for td class attributes
var classes = ["ctr","","","","ctr"];
for (i = 0; i < data.childNodes.length; i++) {
// use only 1st level element nodes to skip 1st level text nodes in NN
if (data.childNodes[i].nodeType == 1) {
// one final match record
oneRecord = data.childNodes[i];
tr = tbody.insertRow(tbody.rows.length);
td = tr.insertCell(tr.cells.length);
td.setAttribute("class",classes[tr.cells.length-1]);
td.innerHTML =
oneRecord.getElementsByTagName("TopicTitle")[0].firstChild.nodeValue ; td = tr.insertCell(tr.cells.length);
td.setAttribute("class",classes[tr.cells.length-1]);
td.innerHTML =
oneRecord.getElementsByTagName("Author")[0].firstChild.nodeValue;
td = tr.insertCell(tr.cells.length);
td.setAttribute("class",classes[tr.cells.length-1]);
td.innerHTML =
oneRecord.getElementsByTagName("Category")[0].firstChild.nodeValue;
td = tr.insertCell(tr.cells.length);

}
}
}

function init(xFile) {
// confirm browser supports needed features and load .xml file
if (verifySupport(xFile)) {
// let file loading catch up to execution thread
setTimeout("drawTable('topics')", 1000);
}
}


</script>
</head>
<body onload="init('latesttopics.xml')">
<h1 align="center">latest Topics</h1>
<hr />

<table style="border-collapse:collapse;" align="center" width="600">
<thead>
<tr><th>TopicTitle</th>
<th>Author</th>
<th>Category</th>
</tr>
</thead>
<tbody id="topics"></tbody>
</table>

<!-- Try to load Msxml.DOMDocument ActiveX to assist support verification -->
<object id="msxml" WIDTH="1" HEIGHT="1"
classid="CLSID:2933BF90-7B36-11d2-B20E-00C04F983E60" ></object>

</body>
</html>


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 06, 2008 9:08 am 
Offline

Joined: Mon May 12, 2008 11:43 am
Posts: 307
Thank you it helps me a lot


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic    [ 2 posts ] 

1, 2, 3, 4, 5 ... 413
Recent topics  Replies   Views   Last post 
No new posts Ecommerce website development and website Design

by iweballey » Fri May 17, 2013 7:15 am in PHP-Code Help

0

130

Fri May 17, 2013 7:15 am

iweballey View the latest post

No new posts How to upgrade and migrate Joomal site

by mallikharjuna rao » Mon Jan 21, 2013 1:40 pm in Joomla

1

344

Thu May 16, 2013 9:53 am

sunitha12 View the latest post

No new posts Benefits of PHP

by hirephpexpert » Fri Sep 07, 2012 4:41 am in CakePHP

6

1569

Wed May 15, 2013 6:25 am

PrettyPrincesG View the latest post

No new posts How to stop user from getting registered in Joomla

by mallikharjuna rao » Tue Jan 22, 2013 5:16 am in Joomla

3

1479

Wed May 15, 2013 6:17 am

PrettyPrincesG View the latest post

No new posts How to write a query in social engine

by fathima_sony » Tue Sep 06, 2011 12:34 pm in Others

2

1756

Tue May 14, 2013 12:09 pm

sanath123 View the latest post


Your Ad Here
cron