Senior & Expert .Net Developers Discussion Forum by Nyros Technologies

HIRE .Net Expert Developers Programmers Coders From India
Ruby on Rails PHP .Net Developers Community, Nyros Technologies, Kakinada
 
Log in  or IF not a member please REGISTER
Username:
Password:   


Keyword
Log in | Profile 

Traversing through XML file using Java Script

 
Post new topic   Reply to topic    Senior & Expert .Net Developers Discussion Forum by Nyros Technologies Index -> XML
View previous topic :: View next topic  
Author Message
david



Joined: 27 Aug 2007
Posts: 14

PostPosted: Wed Apr 01, 2009 4:25 am    Post subject: Traversing through XML file using Java Script Reply with quote

Hi,

I have a XML file with following data.


- <NewDataSet>
- <Table>
<DOCDESC>TEST</DOCDESC>
<DATETIME>03/29/94 12:00:28</DATETIME>
<COMPANY>*</COMPANY>
<PAGE>1</PAGE>
<SECTION>42</SECTION>
<DOCTYPE>G</DOCTYPE>
</Table>
- <Table>
<DOCDESC>TEST1</DOCDESC>
<DATETIME>03/29/94 11:59:44</DATETIME>
<COMPANY>*</COMPANY>
<PAGE>1</PAGE>
<SECTION>44</SECTION>
<DOCTYPE>G</DOCTYPE>
</Table>
</NewDataSet>


I have to create Hyper link for each element of xml file in a html page. please post the code in javascript for this task. it is very urgent.

thanks in advance,


regards,
david
Back to top
View user's profile Send private message Send e-mail
vamsy



Joined: 21 Aug 2007
Posts: 60

PostPosted: Wed Apr 01, 2009 4:28 am    Post subject: Reply with quote

Hi,


here is the code for your requirement. simple copy the code and use it.

note: html file and XML file both should be in same directory.


<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>

<script type="text/javascript" language="javascript">
var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
function loadXML(xmlFile)
{
xmlDoc.async="false";
xmlDoc.onreadystatechange=verify;
xmlDoc.load(xmlFile);
xmlObj=xmlDoc.documentElement;
}

function verify()
{
// 0 Object is not initialized
// 1 Loading object is loading data
// 2 Loaded object has loaded data
// 3 Data from object can be worked with
// 4 Object completely initialized
if (xmlDoc.readyState != 4)
{
return false;
}
}

function display()
{
var len = xmlObj.childNodes.length;

for(var i=0; i<len; i++)
{
document.getElementById('data').innerHTML = document.getElementById('data').innerHTML + " <a href = 'http://www.google.com' style = 'text-decoration:none;'>" + xmlObj.childNodes(i).childNodes(0).firstChild.text + " " + xmlObj.childNodes(i).childNodes(1).firstChild.text+ "</a><br/>";

}
}

</script>

</head>

<body onLoad="loadXML('test.xml');display();">

<div id="data">
</div>


</body>
</html>


I hope this will meet your requirement.

regards,
vamsy
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    Senior & Expert .Net Developers Discussion Forum by Nyros Technologies Index -> XML
Page 1 of 1


 latest topics 
 Topics   Replies   Author   Views   Last Post 
No new posts Exceptional Manger
1 suraj 15 Thu Sep 02, 2010 8:52 am
Rahul View latest post
No new posts background image for UITableView
0 kumar 20 Wed Sep 01, 2010 10:34 am
kumar View latest post
No new posts Types of Run time exceptions
1 Dheeraj 23 Wed Sep 01, 2010 8:58 am
venkat View latest post
No new posts Access Web Page content in Windows Forms without WebBrowser
3 mouli 249 Wed Sep 01, 2010 7:31 am
rajesh View latest post
No new posts Explain Interlocked Class & Daemon Thread's?
1 mukundh 33 Wed Sep 01, 2010 7:19 am
setty View latest post
No new posts Life Cycle Of Delegate
0 vinay 18 Wed Sep 01, 2010 7:14 am
vinay View latest post
No new posts Accessing methods defined in another page
1 suraj 21 Tue Aug 31, 2010 12:45 pm
Rahul View latest post
No new posts How ASP.Net events are processed?
1 Teena 27 Tue Aug 31, 2010 11:55 am
suraj View latest post
No new posts Universal description discovery and integration
1 Dileep 21 Tue Aug 31, 2010 11:45 am
venkat View latest post
No new posts What is the difference between Shadowing and Overriding ?
1 suraj 28 Tue Aug 31, 2010 11:37 am
Teena View latest post




Hire an expert .Net developer / coder / programmer or development team from India now!!

Other Forums : Ruby on Rails   ::   PHP   |   Free unlimited HTML CSS templates download

Nyros Technologies   |   Kakinada City Portal   |   Developers Blog   |   About .Net Experts   |   More