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: 61

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 How to install iPhone SDK?
0 Ramya sree 12 Fri Mar 12, 2010 11:17 am
Ramya sree View latest post
No new posts Parsing XML using SAX parser in Android
0 vijayalakshmi 11 Fri Mar 12, 2010 4:41 am
vijayalakshmi View latest post
No new posts Show Notification in Status Bar in Android Application
0 vijayalakshmi 23 Tue Mar 09, 2010 9:36 am
vijayalakshmi View latest post
No new posts Changing the date and time in SQL Server using T-SQL
0 muralikrishna 35 Fri Mar 05, 2010 3:18 pm
muralikrishna View latest post
No new posts Using TableLayout in Android Layout file:
0 vijayalakshmi 36 Fri Mar 05, 2010 5:03 am
vijayalakshmi View latest post
No new posts TabActivity with Intents in Android:
0 vijayalakshmi 36 Fri Mar 05, 2010 4:46 am
vijayalakshmi View latest post
No new posts Show different components in different styles in Android?
0 vijayalakshmi 35 Fri Mar 05, 2010 3:39 am
vijayalakshmi View latest post
No new posts VIEWSTATE SIZE BYTES SHOWS 0 IN TRACE.AXD
1 sanjoo8959 47 Wed Mar 03, 2010 9:18 am
Dileep View latest post
No new posts How to mark incoming Sms as read in Android programatically?
0 vijayalakshmi 39 Mon Mar 01, 2010 1:12 pm
vijayalakshmi View latest post
No new posts How to control(Start,Stop) windows Services in C#?
0 Raghavendra 45 Mon Mar 01, 2010 12:57 pm
Raghavendra 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