Solved

Read XML into a file

Posted on 2009-06-27
5
239 Views
Last Modified: 2013-11-26
Hello,

(I am a novice still learning)....

Please see the code below. I have an XML data stream coming in from a WebRequest, and I now want to place this stream into a file called response.xml which is located at "C:\XML\response.xml

What is the syntax (in VB.NET) to use the stream writer to place the response into this file?  

Thanks,
Joe
Dim response As WebResponse = request.GetResponse()
        dataStream = response.GetResponseStream()
        Dim reader As XmlTextReader = New XmlTextReader(dataStream)

Open in new window

0
Comment
Question by:NursingCorp
  • 2
  • 2
5 Comments
 
LVL 4

Expert Comment

by:nasserd
ID: 24728195
This MSDN article should have the StreamWriter calls you're looking for.
http://msdn.microsoft.com/en-us/library/6ka1wd3w.aspx
0
 

Author Comment

by:NursingCorp
ID: 24728327
Ok, read the article and tried:

=========================================================================
        Dim response As WebResponse = request.GetResponse()
        dataStream = response.GetResponseStream()
        Dim reader As XmlTextReader = New XmlTextReader(dataStream)

        Using sw As New StreamWriter("C:\XML\response1.xml")
            sw.Write(reader)
        End Using

==========================================================================
And in my file, response.xml, it has the following text:

System.Xml.XmlTextReader
0
 

Author Comment

by:NursingCorp
ID: 24728343
The file is actually response1.xml, not response.xml.
0
 
LVL 4

Accepted Solution

by:
nasserd earned 500 total points
ID: 24729684
"System.Xml.XmlTextReader" is the object's type -- the default information that is output because no property or method is specified.  You need to either read the dataStream object (using .ToString) or loop through the XmlTextReader object to output the appropriate XML nodes.

To better understand GetResponseStream please read:
http://msdn.microsoft.com/en-us/library/system.net.webresponse.getresponsestream.aspx

To better understand XmlTextReader please read:
http://msdn.microsoft.com/en-us/library/system.xml.xmltextreader.aspx
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Publisher:   Unknown     VB.exe Application 1 21
Regular expression help 2 25
start a process from a service 3 23
vb.net and creating a class 5 17
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question