473,473 Members | 1,707 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Gurus for XML TextStream vs Response Stream vs XMLValidatingReader

Hi,

I try retrieve an XML stream from a webapp
using a post
"http://webedu.its.uct.ac.za/webct/public/serve_webctdb?OPERATION=homearea_xml&DB=global&Web CT%20ID=rodgersn_its_main&AUTH=ee09aabc77ef593917a 60720f167c733"

and
result = req.GetResponse()
ReceiveStream = result.GetResponseStream()

from here ..I try read the XML retrieved, but...

I've tried XMLStream and XMLValidatingStream..both return
"There is invalid data at the root level"

Trying a std StreamReader with say .readtoend or
sr.Read(read, 0, 256) in a count loop, I get an error "too few parameters"
on the
string result of the read.

Where do I go from here?
Tia
--
Neal Rogers
University of Cape Town
Nov 12 '05 #1
2 2394


Neal wrote:

I try retrieve an XML stream from a webapp
using a post
"http://webedu.its.uct.ac.za/webct/public/serve_webctdb?OPERATION=homearea_xml&DB=global&Web CT%20ID=rodgersn_its_main&AUTH=ee09aabc77ef593917a 60720f167c733"
That is a URL with a query string so we only know the URL and any data
send with a HTTP GET request. When I load that URL with IE 6 which
parses the XML with MSXML 3 it is loaded without errors. Thus if you get
and
result = req.GetResponse()
ReceiveStream = result.GetResponseStream()

from here ..I try read the XML retrieved, but...

I've tried XMLStream and XMLValidatingStream..both return
"There is invalid data at the root level"
errors with .NET then perhaps the server sends a different response
after your POST request, perhaps an HTTP response with an error code and
a text/html response body which the XML parser can't parse.
So we need to see exactly what you do to see what could go wrong.
Trying a std StreamReader with say .readtoend or
sr.Read(read, 0, 256) in a count loop, I get an error "too few parameters"
on the
string result of the read.


What language are you using? With VB.NET I think you need
Dim responseText As String
responseText = sr.ReadToEnd()
if you want to use a StreamReader.
--

Martin Honnen
http://JavaScript.FAQTs.com/
Nov 12 '05 #2
Hi Martin

Yes, It is a VB.Net app

This is the full rtn's code..
Thanks
Neal

Dim result As WebResponse
Dim req As WebRequest
Dim RequestStream As Stream
Dim ReceiveStream As Stream
Dim encode As Encoding
Dim sr As StreamReader
Dim SomeBytes() As Byte
Dim UrlEncoded As New StringBuilder()
Dim reserved() As Char = {ChrW(63), ChrW(61), ChrW(38)}

req = WebRequest.Create(url)
req.Method = "POST"
req.ContentType = "application/x-www-form-urlencoded" 'The
ContentType property contains the media type of the request

Dim strResult As String

Try
Dim i As Integer = 0
If payload <> Nothing Then
Dim j As Integer
While i < payload.Length
j = payload.IndexOfAny(reserved, i)
If j = -1 Then

UrlEncoded.Append(HttpUtility.UrlEncode(payload.Su bstring(i, payload.Length -
i)))
Exit While
End If

UrlEncoded.Append(HttpUtility.UrlEncode(payload.Su bstring(i, j - i)))
UrlEncoded.Append(payload.Substring(j, 1))
i = j + 1
End While
SomeBytes =
System.Text.Encoding.UTF8.GetBytes(UrlEncoded.ToSt ring())
req.ContentLength = SomeBytes.Length
RequestStream = req.GetRequestStream()
RequestStream.Write(SomeBytes, 0, SomeBytes.Length)
RequestStream.Close()
Else
req.ContentLength = 0
End If

'-- Response Object
result = req.GetResponse()
ReceiveStream = result.GetResponseStream()
encode = System.Text.Encoding.GetEncoding("utf-8")
sr = New StreamReader(ReceiveStream, encode)
Dim xr As New XmlTextReader(New StreamReader(ReceiveStream,
encode))
xr.Normalization = True
If xr.CanResolveEntity Then
xr.ReadStartElement()
strResult = strResult & xr.Value
End If

' 'For DTD....
' Dim vreader As New XmlValidatingReader(xr)
' Dim resolver As New XmlUrlResolver()
' vreader.XmlResolver = resolver

' If vreader.CanResolveEntity Then
' Dim attrCnt As Integer = vreader.AttributeCount
' Dim xBaseUri As String = vreader.BaseURI.ToString
' Dim yLocalNodeName As String = vreader.LocalName.ToString
' Dim sNdType As String = vreader.NodeType.ToString
' 'While vreader.read 'reads the next node from the
stream
' strResult = strResult & vreader.ReadInnerXml() '=
nothing
' strResult = strResult & vreader.Value
'' strResult = strResult & vreader.
' 'End While

' While xr.Read
' strResult = strResult & xr.ReadInnerXml 'str
' 'error: there is invalid data at the root level,
line 1,position 1
' End While
' End If
Catch Exc As Exception
Throw New Exception(Exc.Message)
Finally
If Not result Is Nothing Then
result.Close()
End If
If Not RequestStream Is Nothing Then
RequestStream.Close()
End If
If Not ReceiveStream Is Nothing Then
ReceiveStream.Close()
End If
End Try
Return strResult

"Martin Honnen" wrote:


Neal wrote:

I try retrieve an XML stream from a webapp
using a post
"http://webedu.its.uct.ac.za/webct/public/serve_webctdb?OPERATION=homearea_xml&DB=global&Web CT%20ID=rodgersn_its_main&AUTH=ee09aabc77ef593917a 60720f167c733"


That is a URL with a query string so we only know the URL and any data
send with a HTTP GET request. When I load that URL with IE 6 which
parses the XML with MSXML 3 it is loaded without errors. Thus if you get
and
result = req.GetResponse()
ReceiveStream = result.GetResponseStream()

from here ..I try read the XML retrieved, but...

I've tried XMLStream and XMLValidatingStream..both return
"There is invalid data at the root level"


errors with .NET then perhaps the server sends a different response
after your POST request, perhaps an HTTP response with an error code and
a text/html response body which the XML parser can't parse.
So we need to see exactly what you do to see what could go wrong.
Trying a std StreamReader with say .readtoend or
sr.Read(read, 0, 256) in a count loop, I get an error "too few parameters"
on the
string result of the read.


What language are you using? With VB.NET I think you need
Dim responseText As String
responseText = sr.ReadToEnd()
if you want to use a StreamReader.
--

Martin Honnen
http://JavaScript.FAQTs.com/

Nov 12 '05 #3

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

Similar topics

3
by: risa | last post by:
I tried to read a text file using the Textstream object and each file line has 4 elements. How do I put them in 4 separate table cells? Thand you very much in advance. Risa
9
by: jason | last post by:
how do you use the XmlValidatingReader to validate an XML document that is passed into the XmlValidatingReader constructor? it looks like the normal process is to use an underlying reader, as...
5
by: Geoff | last post by:
I am using an XMLValidatingReader to validate an XML file received via a web service. I want to verify that the incoming file matches the XML schema. When testing the validation routine, the...
1
by: Bernhard Felkel | last post by:
I have troubles validating XML files with key/keyref constraints. Here´s my schema: <?xml version="1.0" encoding="utf-8"?> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"...
7
by: Shapiro | last post by:
I have a scenario where I log a resquest to a database table and update the request with a corresponding response including the response time. I am using an HttpModule to do this. My challenge...
1
by: AspProgrammer | last post by:
Hello I'm writing a web application where i upload a file. then i open the file use textstream. At the end of my application i close it by using TextStream.close. But when i try to delete the...
1
by: Plop69 | last post by:
need some help on following: xml file 1 <TEST xmlns="http://test" > <OK>mlkddflmkj</OK> </TEST> xml file 2
12
by: Plop69 | last post by:
need some help on following: xml file 1 <TEST xmlns="http://test" > <OK>mlkddflmkj</OK> </TEST>
4
by: sham | last post by:
Hi to all, I have a memory Stream that is validated using the XmlValidatingReader object. My stream is passed to the XmlValidatingReader object together with the xsd file. This works fine. ...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...
1
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.