473,326 Members | 2,173 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,326 software developers and data experts.

XmlTextReader URL Limitation???

Q
I am feeding XmlTextReader a URL that returns the XML that then gets parsed.
The URL forms a query that affects how much data is returned in XML but not
the format of the data.

The problem is that when the URL string exceeds about 163 characters
(strange number) XmlTextReader seems to choke on it and it doesn't seem like
any XML is actually being returned and the code throws an exception on
reading the first element. Shorter URL strings seem to work fine. Strings
longer than ~163 chars work fine when pasted into a browser, so the server
is returning good XML.

Sorry for the long post.....
Code, XML, error msg follow:

Imports System
Imports System.Xml
Imports System.Xml.XPath
Imports System.Xml.Xsl
Imports System.Xml.Schema
Imports System.Collections

Module Module1
Sub FPO_XmlQuery()
Dim urlA As String
Dim urlB As String
Dim strMatches As String
Dim intMatchCount As Integer
Dim i As Integer

' this url will work.
urla =
"http://www.freepatentsonline.com/xml-search.pl?type=uspatent&query=ttl/cryo
genic&sort=chron&date_range=all&start=51&session_i d=ABCD123EFGHIJKLMNOPQRSTU
V"
' this url will fail.
urlb =
"http://www.freepatentsonline.com/xml-search.pl?type=uspatent&query=ttl/cryo
genic&stemming=yes&sort=chron&date_range=all&start =51&session_id=ABCD123EFGH
IJKLMNOPQRSTUV"
' both urls return the exact same xml and both work fine if you
paste them into a browser and get the xml back.
' it appears that the length of the url string is an issue for
XmlTextReader.

Dim r As XmlTextReader
r = New XmlTextReader(urlA) ' sub in urlA or urlB here or
"xm1.txt" to read the xml from a local file.
r.ReadStartElement("results") ' this is where the exception
error occurs with the "long" url
strMatches = r.ReadElementString("matches")
Console.WriteLine("matches: {0}", strMatches)
Console.WriteLine("query: {0}", r.ReadElementString("query"))

intMatchCount = 50 ' CInt(strMatches)

For i = 1 To intMatchCount
r.ReadStartElement("uspatent")
Console.WriteLine("match: {0}", r.ReadElementString("match"))
Console.WriteLine("document: {0}",
r.ReadElementString("document"))
Console.WriteLine("title: {0}", r.ReadElementString("title"))
Console.WriteLine("link: {0}", r.ReadElementString("link"))
r.ReadEndElement() ' </uspatent>
Next

r.ReadEndElement() ' </results>

End Sub

Sub Main()
Console.WriteLine("XML tests...")

Console.WriteLine("Free Patent Read *********************")
FPO_XmlQuery()

While (True = True) ' here to keep console window alive.
End While
End Sub

End Module
----------------------------------------------------------------------------
---------
sample of xml returned:

<?xml version="1.0"?>
<results>
<matches>1826</matches>
<query>TTL:cryogen^4.0</query> <uspatent>
<match>51 </match>
<document>6722140</document>
<title><![CDATA[ Cascade cryogenic thermoelectric cooler for cryogenic
and room temperature applications]]></title>
<link>http://www.freepatentsonline.com/us6722140.html</link>
</uspatent>
<uspatent>
<match>52 </match>
<document>6718775</document>
<title><![CDATA[ Dual chamber cooling system with cryogenic and
non-cryogenic chambers for ultra high vacuum system]]></title>
<link>http://www.freepatentsonline.com/us6718775.html</link>
</uspatent>
<uspatent>
<match>53 </match>
<document>6712880</document>
<title><![CDATA[ Cryogenic process utilizing high pressure absorber
column]]></title>
<link>http://www.freepatentsonline.com/us6712880.html</link>
</uspatent>
....
....
....
----------------------------------------------------------------------------
----------------------
Error message text:

Unhandled Exception: System.Net.WebException: The underlying connection was
clos
ed: The server committed an HTTP protocol violation.
at System.Net.HttpWebRequest.CheckFinalStatus()
at System.Net.HttpWebRequest.EndGetResponse(IAsyncRes ult asyncResult)
at System.Net.HttpWebRequest.GetResponse()
at System.Xml.XmlDownloadManager.GetNonFileStream(Uri uri, ICredentials
crede
ntials)
at System.Xml.XmlDownloadManager.GetStream(Uri uri, ICredentials
credentials)

at System.Xml.XmlUrlResolver.GetEntity(Uri absoluteUri, String role, Type
ofO
bjectToReturn)
at System.Xml.XmlTextReader.CreateScanner()
at System.Xml.XmlTextReader.Init()
at System.Xml.XmlTextReader.Read()
at System.Xml.XmlReader.MoveToContent()
at System.Xml.XmlReader.ReadStartElement(String name)
at XMLtest2.Module1.FPO_XmlQuery() in C:\XMLtest\XMLtest2\Module1.vb:line
68
at XMLtest2.Module1.Main() in C:\XMLtest\XMLtest2\Module1.vb:line 94

Nov 12 '05 #1
2 3777
What build are you using please? I transposed your code into C# and this is
no repro for me on Whidbey RTM builds.

C:\>csc FPO_XmlQuery.cs
Microsoft (R) Visual C# 2005 Compiler version 8.00.50727
for Microsoft (R) Windows (R) 2005 Framework version 2.0.50727
Copyright (C) Microsoft Corporation 2001-2005. All rights reserved.

FPO_XmlQuery.cs(17,16): warning CS0219: The variable 'urla' is assigned but
its value is never used

C:\Documents and Settings\alexkr\My Documents\My
Tests\Managed>FPO_XmlQuery.exe
XML tests...
Free Patent Read *********************
matches: 1827
query: TTL:cryogen^4.0
match: 51
document: 6722866
title: Pump system for delivering cryogenic liquids
link: http://www.freepatentsonline.com/us6722866.html

.... <snipped for length> ...

match: 100
document: 6622758
title: Interlock for cryogenic liquid off-loading systems
link: http://www.freepatentsonline.com/us6622758.html

C:\>
"Q" <Q@Q.com> wrote in message news:iv********************@rcn.net...
I am feeding XmlTextReader a URL that returns the XML that then gets
parsed.
The URL forms a query that affects how much data is returned in XML but
not
the format of the data.

The problem is that when the URL string exceeds about 163 characters
(strange number) XmlTextReader seems to choke on it and it doesn't seem
like
any XML is actually being returned and the code throws an exception on
reading the first element. Shorter URL strings seem to work fine.
Strings
longer than ~163 chars work fine when pasted into a browser, so the server
is returning good XML.

Sorry for the long post.....
Code, XML, error msg follow:


Nov 12 '05 #2
Q
I'm using Visual Studio .NET 2003 and .NET v1.1. As it turns out, the error
has nothing to do with XmlTextReader at all. The problem is with the
parsing of http headers in .NET. .Net 1.0 SP3 and .NET 1.1 SP1 tightened up
the parsing of http headers for security reasons (to block out mal-formed
headers). KB 888527 has info about this. The workaround is to set the
useUnsafeHeaderParsing = true in the app.config file as the knowledge-base
article states. The "fix" is to have the XML server send clean http
headers. It would be curious to see if the default behavior for Whidbey has
useUnsafeHeaderParsing = true. That would be a potential security hole
(albeit, maybe a minor one.)

For me, the problem is solved.... Thanks for your response.

"Alex Krawarik [MSFT]" <al****@online.microsoft.com> wrote in message
news:O3**************@TK2MSFTNGP14.phx.gbl...
What build are you using please? I transposed your code into C# and this is no repro for me on Whidbey RTM builds.

C:\>csc FPO_XmlQuery.cs
Microsoft (R) Visual C# 2005 Compiler version 8.00.50727
for Microsoft (R) Windows (R) 2005 Framework version 2.0.50727
Copyright (C) Microsoft Corporation 2001-2005. All rights reserved.

FPO_XmlQuery.cs(17,16): warning CS0219: The variable 'urla' is assigned but its value is never used

C:\Documents and Settings\alexkr\My Documents\My
Tests\Managed>FPO_XmlQuery.exe
XML tests...
Free Patent Read *********************
matches: 1827
query: TTL:cryogen^4.0
match: 51
document: 6722866
title: Pump system for delivering cryogenic liquids
link: http://www.freepatentsonline.com/us6722866.html

... <snipped for length> ...

match: 100
document: 6622758
title: Interlock for cryogenic liquid off-loading systems
link: http://www.freepatentsonline.com/us6622758.html

C:\>
"Q" <Q@Q.com> wrote in message news:iv********************@rcn.net...
I am feeding XmlTextReader a URL that returns the XML that then gets
parsed.
The URL forms a query that affects how much data is returned in XML but
not
the format of the data.

The problem is that when the URL string exceeds about 163 characters
(strange number) XmlTextReader seems to choke on it and it doesn't seem
like
any XML is actually being returned and the code throws an exception on
reading the first element. Shorter URL strings seem to work fine.
Strings
longer than ~163 chars work fine when pasted into a browser, so the server is returning good XML.

Sorry for the long post.....
Code, XML, error msg follow:


Nov 12 '05 #3

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

Similar topics

4
by: Andy Neilson | last post by:
I've run across a strange behaviour with XmlSerializer that I'm unable to explain. I came across this while trying to use XmlSerializer to deserialize from a the details of a SoapException. This...
5
by: Geoff Bennett | last post by:
While parsing an XML document, my TextReader instance skips nodes. For example, in this fragment: <Person Sex="Male" FirstHomeBuyer="No" YearsInCurrentProfession="14"> <RelatedEntityRef...
2
by: Yuriy | last post by:
Hi, any ideas how to read XML fragment from TextReader? XmlTextReader constructor accepts only Stream or string as source Do I miss something? thanks Yuriy
1
by: RJN | last post by:
Hi I'm using XMLTextReader to parse the contents of XML. I have issues when the xml content itself has some special characters like & ,> etc. <CompanyName>Johnson & Jhonson</CompanyName>...
1
by: SHC | last post by:
Hi all, I did the "Build" on the attached code in my VC++ .NET 2003 - Windows XP Pro PC. On the c:\ screen, I got the following: Microsoft Development Environment An unhandled exception of type...
3
by: Kjeld | last post by:
My scenario: I'm using an XmlTextReader to Deserialize serveral classes from a single xml document. Every class i pass the source stream, containing the xml. Each class subsequently creates an...
2
by: XML reading with XMLTextReader | last post by:
im trying to read an xml file which is in the wwwroot folder.im using IIS on XP Prof. my code is...
4
by: CodeRazor | last post by:
I am reading an xml file from a URL. I was originally doing this using the XmlDocument class. But this was very slow. The XmlTextReader is meant to be much quicker for forward only retrieval of...
4
by: CodeRazor | last post by:
I am trying to use an XmlTextReader to retrieve data. I need to use an XmlTextReader because it is faster than using an XmlDocument. I have found an inelegant way of retrieving each item's title...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.