.NET Framework Bookmark and Share   
 index > JScript for the .NET Framework > How to Read XML through Javascript
 

How to Read XML through Javascript

i am using Ajax. I get the XML formatted data using XMLHttpRequest object(ResponseXML) using the line :
var objDepartment=XMLHttpRequest.ResponseXML

. That XML formatted data we r creating in server side.
it's structure is
<Department>
<name>name1</name>
<code>code1</code>
</Department>

Now using javascript how to read the elements from objDepartment ?
Please help.
pongopiprakash

If yousearch the webfor XmlHttpRequesttutorial, you'll find a bunch of examples. Here's one: http://www.alistapart.com/articles/gettingstartedwithajax

Rok Yu

If yousearch the webfor XmlHttpRequesttutorial, you'll find a bunch of examples. Here's one: http://www.alistapart.com/articles/gettingstartedwithajax

Rok Yu

You can parse XML file in JavaScript with this code

function showName(){

var xmlDoc=new ActiveXObject("MSXML.DOMDocument");
xmlDoc.async="false";
xmlDoc.load("abc.xml");
var students=xmlDoc.documentElement;
var student = students.childNodes(0);
document.getElementById("NamelH1").innerHTML = student.getElementsByTagName("Name")[0].text;
document.getElementById("HostelH1").innerHTML = student.getElementsByTagName("Hostel")[0].text;
document.getElementById("ContactH1").innerHTML = student.getElementsByTagName("Contact")[0].text;
}

You can get complete tutorial at my blog http://binodsuman.blogspot.com/2009/05/parse-xml-response-in-javasript.html

Thanks,

Binod Suman
http://binodsuman.blogspot.com
Binod Suman
You can use getElementsByTagName to read the child node element . like

var name = objDepartment.getElementsByTagName("name");
varcode = objDepartment.getElementsByTagName("code");



Regards,
Kundan Sinha
www.java-script.in

Kundan Sinha www.java-script.in
  • Proposed As Answer byKundan Sinha Monday, June 15, 2009 5:32 PM
  •  
Kundan Sinha

You can use google to search for other answers

Custom Search

More Threads

• How to execute javascript when a Page Loads?
• help on html to excel
• Javascript smart indenting in visual studio 2005
• Application is running only using portnumber not using localhost
• ShowModalDialog - Select Text
• js for private area
• JScript.NET Editor?
• Fading between Views.
• Ultimate Script for "continuous" Asyncrhonous Callback using microsoft.XMLHTTP
• Trouble Retrieving Hidden Field Value