C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |



My Profile

Gifts

Active Members
TodayLast 7 Days more...









Display XML Data in HTML page


Posted Date: 18 Jul 2008    Resource Type: Code Snippets    Category: XML

Posted By: Kundan Kumar Sinha       Member Level: Gold
Rating:     Points: 8



Copy the following java script code in a HTML File in the head section between the script tag (in a file, say, "Test.html"). Also add three span tags with id="to", id="from" and id="state" respectively. The LoadXML() function in the code sample creates a Microsoft XMLDOM object, which reads a XML file and displays the data in a html file.




function LoadXML()
{
var xmlDoc = new ActiveXObject("Microsoft.XMLDOM")
xmlDoc.async="false"
xmlDoc.load("test.xml")
nodes = xmlDoc.documentElement.childNodes

to.innerText = nodes.item(0).text
from.innerText = nodes.item(1).text
state.innerText = nodes.item(2).text

}



Add the function line inside the body tag.

onload="LoadXML()"


Save the following content as test.xml in the same folder where you saved the test.html


<?xml version="1.0" encoding="ISO8859-1" ?>
<note>
<name>Kundan Kumar Sinha</name>
<place>Bangalore</place>
<state>Karnataka</state>
</note>



Now open the test.html file in a browser.





Responses

Author: Praneeth    30 Jul 2008Member Level: Bronze   Points : 1
Hi I've done the same as you said....but Ia m getting an error saying "Object expected"....awaiting for teh reason and solution


thanks


Author: Kundan Kumar Sinha    01 Aug 2008Member Level: Gold   Points : 1
Hi Praneeth,

I think Microsoft.XMLDOM object is not getting created. This code will work with IE. If you are using some other browser, kindly try with IE.

If still you face problem, kindly let me know.

Regards,
Kundan


Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Display XML Data in HTML using Javascript  .  Display XML Data in HTML  .  Display XML Data in a Web Page using Javascript  .  Display XML Data in a Web Page  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Create XML File in C#.NET using XmlTextWriter
Previous Resource: XML Parsing
Return to Discussion Resource Index
Post New Resource
Category: XML


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design

accuconference

Contact Us    Privacy Policy    Terms Of Use