how to retrieve and display XML using C#?http://forums.asp.net/t/1765072.aspx/1?how+to+retrieve+and+display+XML+using+C+Mon, 20 Feb 2012 19:02:41 -050017650724812348http://forums.asp.net/p/1765072/4812348.aspx/1?how+to+retrieve+and+display+XML+using+C+how to retrieve and display XML using C#? <p>well the problem is that I am new to asp.net technology and I am stuck on a problem.</p> <p>&nbsp;</p> <p>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 :(&nbsp;</p> <p>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.</p> 2012-02-02T09:30:43-05:004812541http://forums.asp.net/p/1765072/4812541.aspx/1?Re+how+to+retrieve+and+display+XML+using+C+Re: how to retrieve and display XML using C#? <p>Hi,</p> <p>Just follow this link&nbsp;</p> <p><a href="http://www.hookedonlinq.com/LINQtoXML5MinuteOverview.ashx">http://www.hookedonlinq.com/LINQtoXML5MinuteOverview.ashx</a>&nbsp;</p> <p><a href="http://www.mssqltips.com/sqlservertip/1524/reading-xml-documents-using-linq-to-xml/">http://www.mssqltips.com/sqlservertip/1524/reading-xml-documents-using-linq-to-xml/</a></p> <p>i hope it helps you</p> <p>&nbsp;</p> 2012-02-02T11:08:26-05:004812613http://forums.asp.net/p/1765072/4812613.aspx/1?Re+how+to+retrieve+and+display+XML+using+C+Re: how to retrieve and display XML using C#? <p>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.</p> 2012-02-02T11:49:15-05:004812624http://forums.asp.net/p/1765072/4812624.aspx/1?Re+how+to+retrieve+and+display+XML+using+C+Re: how to retrieve and display XML using C#? <p>Hello,</p> <p>&nbsp;</p> <p>Which browser you are using IE is Support XML file &nbsp;it will display the xml result.</p> <p>suppose if you are using any handlers</p> <p>use this line</p> <p>context.Response.ContentType = &quot;text/xml&quot;;</p> <p>it ll give you the xml result.</p> <p>&nbsp;</p> 2012-02-02T11:54:25-05:004812630http://forums.asp.net/p/1765072/4812630.aspx/1?Re+how+to+retrieve+and+display+XML+using+C+Re: how to retrieve and display XML using C#? <p>No I dont know how to use handlers</p> 2012-02-02T11:58:35-05:004812646http://forums.asp.net/p/1765072/4812646.aspx/1?Re+how+to+retrieve+and+display+XML+using+C+Re: how to retrieve and display XML using C#? <p>Hello,</p> <p>&nbsp;</p> <p>How you send the requset to different server?</p> <p>would you please post what you get the respose from that server.&nbsp;</p> <p>it ll easy to guide you.</p> 2012-02-02T12:07:02-05:004812668http://forums.asp.net/p/1765072/4812668.aspx/1?Re+how+to+retrieve+and+display+XML+using+C+Re: how to retrieve and display XML using C#? <p>&nbsp;</p> <pre class="prettyprint">string url = &quot;http://example.com/CDATA&quot;; WebRequest req = HttpWebRequest.Create(&quot;http://example.com/CDATA&quot;); 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);</pre> <p>it simply gives an error when I try to use the str argument</p> <p>and this below is the outoput that I get</p> <p><span>System.Xml.XmlTextReaderImpl</span></p> <p>&nbsp;</p> 2012-02-02T12:18:23-05:004812729http://forums.asp.net/p/1765072/4812729.aspx/1?Re+how+to+retrieve+and+display+XML+using+C+Re: how to retrieve and display XML using C#? <p>Hello,</p> <p>&nbsp;</p> <p>You need to create the handler for like this</p> <p><a href="http://www.dotnetperls.com/ashx">http://www.dotnetperls.com/ashx</a></p> <p>and then create you what ever yiou want&nbsp;</p> <p>&nbsp;</p> <p>import thing is you need to add&nbsp;</p> <pre>context.Response.ContentType = &quot;text/xml&quot;;</pre> 2012-02-02T12:44:06-05:004813899http://forums.asp.net/p/1765072/4813899.aspx/1?Re+how+to+retrieve+and+display+XML+using+C+Re: how to retrieve and display XML using C#? <p>Hi</p> <p></p> <p>Follow this link&nbsp;</p> <p><a href="http://www.4guysfromrolla.com/articles/092403-1.aspx#postadlink">http://www.4guysfromrolla.com/articles/092403-1.aspx#postadlink</a></p> <p></p> 2012-02-03T04:19:23-05:004815627http://forums.asp.net/p/1765072/4815627.aspx/1?Re+how+to+retrieve+and+display+XML+using+C+Re: how to retrieve and display XML using C#? <p>please see this</p> <p>http://www.codeproject.com/Articles/7718/Using-XML-in-C-in-the-simplest-way</p> <p></p> 2012-02-03T22:29:54-05:004815703http://forums.asp.net/p/1765072/4815703.aspx/1?Re+how+to+retrieve+and+display+XML+using+C+Re: how to retrieve and display XML using C#? <p></p> <blockquote><span class="icon-blockquote"></span> <h4>mamoorkhan</h4> 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 :(&nbsp;</blockquote> <p></p> <p>There are mainly three ways</p> <p>1If your xml is very regularyou can use DataSet.ReadXml to read all the things in and then deal with the DataTable inside the DataSet</p> <p>2Use XmlDocument</p> <p>3Use XDocument</p> <p>Reguards</p> 2012-02-04T01:16:01-05:004841752http://forums.asp.net/p/1765072/4841752.aspx/1?Re+how+to+retrieve+and+display+XML+using+C+Re: how to retrieve and display XML using C#? <p>I'm bumping this thread because it's really similar to what I'm also trying to figure out. Here is the code I'm testing:</p> <pre class="prettyprint">using System; using System.Xml; using System.Xml.Linq; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleLINQtoXML { class Program { static void Main(string[] args) { // Create the query var records = from c in XElement.Load(&quot;xmlTest.xml&quot;).Elements(&quot;record&quot;) select c; //Execute the query foreach (var record in records) { Console.WriteLine(record); } //Pause the application Console.ReadLine(); } } }</pre> <p>And here is some of the XML I'm trying to read from:</p> <pre class="prettyprint">&lt;?xml version="1.0" encoding="UTF-8" ?&gt; &lt;xml&gt; &lt;records&gt; &lt;record&gt; &lt;database name="CMF 2011 Copy 3.enl" path="C:\Users\Ellen Van Alstyne\Documents\SRI writing\TraumaLine or spineline summaries from Aaron\TL and SL and CMFL arrived 7-13-2011\CMF 2011 Copy 3.enl"&gt;CMF 2011 Copy 3.enl&lt;/database&gt; &lt;source-app name="EndNote" version="14.0"&gt;EndNote&lt;/source-app&gt; &lt;rec-number&gt;1&lt;/rec-number&gt; &lt;foreign-keys&gt; &lt;key app="EN" db-id="9p5z2tt9iddpaxeaxpdxrrr00vwx29zxedfx"&gt;1&lt;/key&gt; &lt;/foreign-keys&gt; &lt;ref-type name="CMFDiagnosis"&gt;53&lt;/ref-type&gt; &lt;contributors&gt; &lt;authors&gt; &lt;author&gt; &lt;style face="normal" font="default" size="100%"&gt;Bhagol, A.&lt;/style&gt; &lt;/author&gt; &lt;author&gt; &lt;style face="normal" font="default" size="100%"&gt;Singh, V.&lt;/style&gt; &lt;/author&gt; &lt;author&gt; &lt;style face="normal" font="default" size="100%"&gt;Kumar, I.&lt;/style&gt; &lt;/author&gt; &lt;author&gt; &lt;style face="normal" font="default" size="100%"&gt;Verma, A.&lt;/style&gt; &lt;/author&gt; &lt;/authors&gt; &lt;/contributors&gt;</pre> <p>If I set .Elements(&quot;record&quot;) to .Elements(&quot;records&quot;), this program will return everything. But If I set it TO ANYTHING ELSE, it will return nothing.&nbsp;</p> <p></p> <p>All I want to do it pull out the individual author names, and save them somewhere I can access them. How can I do this? None of these sources are helping at all, because for some reason I can't return any of the values from my XML. For example, var authorName = Element(&quot;author&quot;).Value;....does not work.</p> <p></p> <p>Thanks.</p> 2012-02-20T19:02:41-05:00