Solved

Read XML into a file

Posted on 2009-06-27
5
227 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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

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.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

762 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now