StreamReader and reading an XML file StreamReader and reading an XML file xml xml

StreamReader and reading an XML file


You have called ReadToEnd(), hence consumed all the data (into a string). This means the reader has nothing more to give. Just: don't do that. Or, do that and use LoadXml(reaponseString).


The Load method is capable of fetching XML documents from remote resources. So you could simplify your code like this:

var xmlDoc = new XmlDocument();xmlDoc.Load("http://example.com/foo.xml");var address = xmlDoc.GetElementsByTagName("original");

No need of any WebRequests, WebResponses, StreamReaders, ... (which by the way you didn't properly dispose). If this doesn't work it's probably because the remote XML document is not a real XML document and it is broken.


If you do it with the exact code you pasted in your question, then the problem is that you first read the whole stream into string, and then try to read the stream again when callingxmlDoc.Load(responseReader)

If you have already read the whole stream to the string, use that string to create the xml documentxmlDoc.Load(responseString)