VB.Net - Getting data from streamreader

Hi Experts.     I have used the following code from MSDN and correctly get the xml file as a response.   I don't need the xml file as such but only need to get the values.  Is there a way of extracting any required data contained in the streamreader before it is written to the xml file.  Or maybe writing the xml file to memory and reading it from there.   Writing the xml file to disk, extracting the data and then deleting the file, seems to be a waste.  Many Thanks

' Create a 'WebRequest' object with the specified url
Dim myWebRequest As WebRequest = WebRequest.Create("www.contoso.com")

' Send the 'WebRequest' and wait for response.
Dim myWebResponse As WebResponse = myWebRequest.GetResponse()

' Call method 'GetResponseStream' to obtain stream associated with the response object
Dim ReceiveStream As Stream = myWebResponse.GetResponseStream()

Dim encode As Encoding = System.Text.Encoding.GetEncoding("utf-8")

' Pipe the stream to a higher level stream reader with the required encoding format.
Dim readStream As New StreamReader(ReceiveStream, encode)
Console.WriteLine(ControlChars.Cr + "Response stream received")
Dim read(256) As [Char]

' Read 256 charcters at a time    .
Dim count As Integer = readStream.Read(read, 0, 256)
Console.WriteLine("HTML..." + ControlChars.Lf + ControlChars.Cr)
While count > 0

    ' Dump the 256 characters on a string and display the string onto the console.
    Dim str As New [String](read, 0, count)
    count = readStream.Read(read, 0, 256)

End While

' Release the resources of stream object.

 ' Release the resources of response object.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Robert SchuttSoftware EngineerCommented:
After this line:
Dim ReceiveStream As Stream = myWebResponse.GetResponseStream()

Open in new window

try this code instead of the rest that's there now:
        Dim xmlDoc As New System.Xml.XmlDocument

Open in new window

From that xml document (in memory) you can get any info you need, a good starting point if needed: the XmlDocument documentation.

Alternatively (mainly if it's a very large xml document) you can use:
Dim xr As New System.Xml.XmlTextReader(ReceiveStream)

Open in new window

But that needs a bit more effort to process, see the XmlTextReader documentation.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.