Solved

Read XML into a file

Posted on 2009-06-27
5
241 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

756 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