473,394 Members | 1,641 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

How do I load the XML got by HttpWebResponse read into a StreamRea

ss
Hi,

I would like to know like How do I load the XML Response which I got from
HttpWebResponse?

What I am doing, I will just put for your perusal;

Dim hwrRequest As HttpWebRequest =
CType(HttpWebRequest.Create("https://someurl"), HttpWebRequest)

hwrRequest.Method = "POST"
hwrRequest.ContentType = "text/xml"

Dim encoding As UTF8Encoding = New UTF8Encoding
Dim postBytes() As Byte = encoding.GetBytes(strReq)

hwrRequest.ContentLength = postBytes.Length

Dim postStream As Stream = hwrRequest.GetRequestStream()
postStream.Write(postBytes, 0, postBytes.Length)
postStream.Close()
Dim hwrResponse As HttpWebResponse = CType(hwrRequest.GetResponse(),
HttpWebResponse)
Dim responseStream As Stream = hwrResponse.GetResponseStream()
Dim sr As StreamReader = New StreamReader(responseStream)
Dim respString As String = sr.ReadToEnd()


''Me.TextBox1.Text = respString

'' here If I am populating in the Multiline Textbox , I am getting the XML
Response

But What I want is directly consume that XML Response into the DOM
XmlDocument.

I tried passing the StreamReader into the Load Method of XmlDocument, but
it gives me the error.

Dim xDoc As New XmlDocument
xDoc.PreserveWhitespace = True
xDoc.Load(respString)
AddText("XML Content", xDoc.OuterXml)

hwrResponse.Close()

Any help would be of great help to me

bye
ss
May 24 '06 #1
2 10290
The Load method of XmlDocument states

[Visual Basic]
Overloads Public Overridable Sub Load( ByVal inStream As Stream )

Therefore perhaps see if you can just use:
xDoc.Load(hwrResponse.GetResponseStream())

Let us know if this works !

However I think there is an error in your code shown
xDoc.Load(respString)


when I think you meant to say
xDoc.Load(sr)

Dickster

May 25 '06 #2
ss
Hi,

Thanks for your reply. I tried that, but it is giving the error like below

The root element is missing.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information about
the error and where it originated in the code.

Exception Details: System.Xml.XmlException: The root element is missing.

Source Error:
Line 187: Dim xDoc As New XmlDocument
Line 188: xDoc.PreserveWhitespace = True
Line 189: xDoc.Load(hwrResponse.GetResponseStream())
Line 190: AddText("XML Content", xDoc.OuterXml)

bye
ss

"dickster" wrote:
The Load method of XmlDocument states

[Visual Basic]
Overloads Public Overridable Sub Load( ByVal inStream As Stream )

Therefore perhaps see if you can just use:
xDoc.Load(hwrResponse.GetResponseStream())

Let us know if this works !

However I think there is an error in your code shown
xDoc.Load(respString)


when I think you meant to say
xDoc.Load(sr)

Dickster

May 29 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Denny Rue | last post by:
I’ve created VB code to download files from a web site through the use of HTTPWebRequest, HTTPWebResponse and BinaryReader. The HTTPWebRequest has a TimeOut property to limit how long it waits...
0
by: hlabbott | last post by:
Hi I'm having a problem displaying attachments correctly. I have messages with attachments stored on Exchange2000 and want to be able to click a hyperlink in my project like in OWA and see an...
0
by: Nathan | last post by:
This is a copy of a message at microsoft.public.dotnet.framework.clr: THE CODE: I'm using an HttpWebResponse object to send an HTTP POST to a Java server I have written and are running on the...
13
by: Jason Manfield | last post by:
For some URLs (e.g.http://v3.espacenet.com/origdoc?DB=EPODOC&IDX=WO2005028634&F=0&QPN=WO2005028634), the content length for the HttpWebResponse I get with request.GetResponse in empty. The...
2
by: stevag | last post by:
Hello, I am developing an application whose main goal is to read from a dynamic ..asp Internet URL. This URL automatically produces an RSS file, which I further want to load into my application...
2
by: Noggin The Nog | last post by:
Hi all, I've been trying to get HttpWebResponse to work, but whenever I try I get "The operation has timed-out". I'm simply trying to send an HTTP request querystring to a remote website and read...
2
by: STEVE.KING | last post by:
Greetings: I need to download an executable and some other binary files (a C++ DLL) from a virtual directory in my WinForms application. No-Touch Deployment manages my .NET code fine but...
2
by: Nuno Magalhaes | last post by:
In pages that there is no content length, how does HttpWebResponse knows where the page ends? And what kind of objects/methods does it retrieve? Does it only retrieve the initial page without any...
3
by: markpittsnh | last post by:
I am using C# to load a url. My URL is an XML document which contains the processing instruction<?xml-Stylesheet type="text/xsl" href=".\CS_Xml_Output.xsl"?> During development, I was using...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.