Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Read XML into a file

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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…
Suggested Courses

704 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