Menu

XML To HTML without using xslt

Hello Friend ,

you have convert XML To HTML without using xslt using following step.

First step . create one xml file

user.xml


<?xml version="1.0" standalone="yes"?>
<NewDataSet>
<User>
<id>3</id>
<UserName>sandeep bhadad</UserName>
</User>
<User>
<id>4</id>
<UserName>ANIMESH</UserName>
</User>
<User>
<id>6</id>
<UserName>TI</UserName>
</User>
<User>
<id>7</id>
<UserName>YA</UserName>
</User>
<User>
<id>8</id>
<UserName>san1235689</UserName>
</User>
<User>
<id>9</id>
<UserName>san12356891</UserName>
</User>
<User>
<id>10</id>
<UserName>bha</UserName>
</User>
</NewDataSet>

Second add some code in “html” page like.


<html>
<head>

<script type="text/javascript">
if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
xmlhttp1 = new XMLHttpRequest();
}
else {// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
xmlhttp1 = new ActiveXObject("Microsoft.XMLHTTP");
}
var URL = "DatabaseToXml.aspx";
xmlhttp1.open('GET', URL, false);
xmlhttp1.send('');
xmlhttp.open("GET", "User.xml", false);
xmlhttp.send();
xmlDoc = xmlhttp.responseXML;

x = xmlDoc.getElementsByTagName("User");
i = 0;
function getUser() {
artist = (x[i].getElementsByTagName("id")[0].childNodes[0].nodeValue);
title = (x[i].getElementsByTagName("UserName")[0].childNodes[0].nodeValue);

txt = "User Id: " + artist + "<br />User Name: " + title;
document.getElementById("UserInfo").innerHTML = txt;

}

function next() {
if (i < x.length - 1) {
i++;
getUser();
}
}

function previous() {
if (i > 0) {
i--;
getUser();
}
}
</script>

<style id='flashfirebugstyle' type='text/css'>
object, embed
{
visibility: hidden !important;
}
</style>

<script type='text/javascript'>        window.addEventListener('load', function() { document.addEventListener('DOMNodeInserted', function(e) { if (e.target.tagName.toLowerCase() == 'object' || e.target.tagName.toLowerCase() == 'embed') { try { FlashFirebug_init(); } catch (e) { } } }, false); try { FlashFirebug_init(); } catch (e) { } }, false);</script>

</head>
<body onload="getUser()">
<div id='UserInfo'>
</div>
<br />
<input type="button" onclick="previous()" value="<<" />
<input type="button" onclick="next()" value=">>" />
</body>
</html>

No comments

Leave a Reply


− 2 = 3

Categories