Click here to Skip to main content
15,880,891 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
ResponseFile.aspx.cs
--------------------

C#
protected void Page_Load(object sender, EventArgs e)
{

string xmlString = "<?xml version=\"1.0\"?><company><employee id=\"001\" >John</employee><employee id=\"002\" >Mike</employee></company>";

Response.Write(xmlString);

}



====================================================================================

JavaScript Code Portion in Default.aspx

C#
if(xmlHttpRequest.readyState == 4)
            {
                var response = xmlHttpRequest.responseXML;

                var doc = response.documentElement;

                var Suggestion = doc.getElementsByTagName('Suggestion')[0].nodeValue;

                document.getElementById('SuggestionBox').innerHTML = Suggestion;
            }




I am getting problems in reading the XML data which we get as a response from the ResponseFile.aspx.cs

How to read the node employee??
Posted
Updated 26-Jul-11 2:33am
v4
Comments
Kim Togo 26-Jul-11 8:18am    
Is this not a JavaScript question ?

1 solution

Before writing your xmlString string you need to clear all response otherwise response string contain html tags and also you need to set content type of response to xml, I suggest this way to get xml from server.

protected void Page_Load(object sender, EventArgs e)
    {
        Response.Clear();
        Response.ContentType = "text/xml";
        XmlDocument Xdoc = new XmlDocument();
        string xmlString = "<?xml version=\"1.0\"?><company><employee id=\"001\" >John</employee><employee id=\"002\" >Mike</employee></company>";
        Xdoc.LoadXml(xmlString);
        Xdoc.Save(Response.OutputStream);
        Response.End();
    }

Example of Retrieve the content of an XML file
http://www.w3schools.com/ajax/tryit.asp?filename=tryajax_xml2[^]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900