well the problem is that I am new to asp.net technology and I am stuck on a problem.
Now the scenario is that I have to send an HTTPrequest to another server from my page, lets say myGames.aspx and in response to the request the server sends me an XML file. Now I don't know how to handle this situation, I mean I am like a total noob :(
also I don't have just to display the data, I have to send different fields of the XML to different databse tables, but thats a later issue, I'd first like to play with the XML data just on screen.
I googled and tried a lots of approaches but the problem is that my browser isn't displaying the the XML. I just can't catch the data in XML format. if I convert it to string then its printed just fine, but I dont want that, all I want is a solution to HOW
TO HANDLE THE RESPONDED BACK XML FILE AS A RESULT OF HTTP REQUEST.
mamoorkhan
Member
64 Points
52 Posts
how to retrieve and display XML using C#?
Feb 02, 2012 09:30 AM|LINK
well the problem is that I am new to asp.net technology and I am stuck on a problem.
Now the scenario is that I have to send an HTTPrequest to another server from my page, lets say myGames.aspx and in response to the request the server sends me an XML file. Now I don't know how to handle this situation, I mean I am like a total noob :(
also I don't have just to display the data, I have to send different fields of the XML to different databse tables, but thats a later issue, I'd first like to play with the XML data just on screen.
dinakaran
Member
625 Points
216 Posts
Re: how to retrieve and display XML using C#?
Feb 02, 2012 11:08 AM|LINK
Hi,
Just follow this link
http://www.hookedonlinq.com/LINQtoXML5MinuteOverview.ashx
http://www.mssqltips.com/sqlservertip/1524/reading-xml-documents-using-linq-to-xml/
i hope it helps you
mamoorkhan
Member
64 Points
52 Posts
Re: how to retrieve and display XML using C#?
Feb 02, 2012 11:49 AM|LINK
I googled and tried a lots of approaches but the problem is that my browser isn't displaying the the XML. I just can't catch the data in XML format. if I convert it to string then its printed just fine, but I dont want that, all I want is a solution to HOW TO HANDLE THE RESPONDED BACK XML FILE AS A RESULT OF HTTP REQUEST.
dinakaran
Member
625 Points
216 Posts
Re: how to retrieve and display XML using C#?
Feb 02, 2012 11:54 AM|LINK
Hello,
Which browser you are using IE is Support XML file it will display the xml result.
suppose if you are using any handlers
use this line
context.Response.ContentType = "text/xml";
it ll give you the xml result.
mamoorkhan
Member
64 Points
52 Posts
Re: how to retrieve and display XML using C#?
Feb 02, 2012 11:58 AM|LINK
No I dont know how to use handlers
dinakaran
Member
625 Points
216 Posts
Re: how to retrieve and display XML using C#?
Feb 02, 2012 12:07 PM|LINK
Hello,
How you send the requset to different server?
would you please post what you get the respose from that server.
it ll easy to guide you.
mamoorkhan
Member
64 Points
52 Posts
Re: how to retrieve and display XML using C#?
Feb 02, 2012 12:18 PM|LINK
string url = "http://example.com/CDATA"; WebRequest req = HttpWebRequest.Create("http://example.com/CDATA"); WebResponse res = req.GetResponse(); StreamReader sr = new StreamReader(res.GetResponseStream()); string str = sr.ReadToEnd(); XmlReaderSettings readerSettings = new XmlReaderSettings(); readerSettings.IgnoreWhitespace = true; XmlReader reader = XmlReader.Create(sr); //XmlReader reader = XmlReader.Create(str); //XmlReader reader = XmlReader.Create(url); Response.Write(reader);it simply gives an error when I try to use the str argument
and this below is the outoput that I get
System.Xml.XmlTextReaderImpl
dinakaran
Member
625 Points
216 Posts
Re: how to retrieve and display XML using C#?
Feb 02, 2012 12:44 PM|LINK
Hello,
You need to create the handler for like this
http://www.dotnetperls.com/ashx
and then create you what ever yiou want
import thing is you need to add
dinakaran
Member
625 Points
216 Posts
Re: how to retrieve and display XML using C#?
Feb 03, 2012 04:19 AM|LINK
Hi
Follow this link
http://www.4guysfromrolla.com/articles/092403-1.aspx#postadlink
tom22
Member
246 Points
70 Posts
Re: how to retrieve and display XML using C#?
Feb 03, 2012 10:29 PM|LINK
please see this
http://www.codeproject.com/Articles/7718/Using-XML-in-C-in-the-simplest-way