Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Read XML into a file

Posted on 2009-06-27
5
Medium Priority
?
252 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
4 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 2000 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

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

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

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.
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

877 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