472,780 Members | 2,058 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

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 2364


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
by: Rina0 | last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth

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.