473,545 Members | 2,663 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Reading XML document with blank lines at top

I am trying to read an XML document generated by a web server using the
XMLTextReader class, but the document generated appears to have some blank
lines at the top that are causing problems.

If I connect directly to the URL, when I call the ".Read" method on the
XMLTextReader, I get the message:

"The XML declaration is unexpected. Line 8, Column 3"

If I open the URL in my browser and copy and paste the XML stuff (starting
with <?xml...) to a text file, save it locally and then access that file
using the XMLText Reader, all is well. It appears as if a bunch (7,
actually) of blank lines are prepended to the top of the file from the web
server so that they appear before the <?xml... declaration.

Is this an an example of a non-well-formed document?

Is there a way to have the XMLTextReader skip over these lines, or is there
a way for me to intercept the stream and only start parsing at the
appropriate point?

Thanks,
Ryan

BTW, I am specifically trying to call the APIs from BMC's Patrol Express
product which return an XML document.
Nov 20 '05 #1
4 3219
Ryan S wrote:
I am trying to read an XML document generated by a web server using
the XMLTextReader class, but the document generated appears to have
some blank lines at the top that are causing problems.

If I connect directly to the URL, when I call the ".Read" method on
the XMLTextReader, I get the message:

"The XML declaration is unexpected. Line 8, Column 3"

If I open the URL in my browser and copy and paste the XML stuff
(starting with <?xml...) to a text file, save it locally and then
access that file using the XMLText Reader, all is well. It appears
as if a bunch (7, actually) of blank lines are prepended to the top
of the file from the web server so that they appear before the
<?xml... declaration.

Is this an an example of a non-well-formed document?


It should work, as far as I know.

Are you sure they're blank lines, and not HTTP headers? Headers would
confuse the hell out of an XmlReader, and would also indeed not show if you
copy/past the URL in a browser.

--
Sven Groot

http://unforgiven.bloghorn.com

Nov 20 '05 #2
Sven,

It does not appear that they are HTTP headers. When I view the source
(using both IE and Mozilla). I definetly see 7 blank lines above the <?xml
.... > line. I also packet sniffed the transaction between the server and my
broswer, I definetly see a bunch of CrLf characters being sent just prior to
<?xml. I also some HTTP packet headers like Server:, Content-Type: and
others. Will these headers cause trouble? If so, any suggestions on
passing over them to get to the XML stuff?

-Ryan

"Sven Groot" <sv*******@gmx. net> wrote in message
news:Oi******** ******@TK2MSFTN GP10.phx.gbl...
Ryan S wrote:
I am trying to read an XML document generated by a web server using
the XMLTextReader class, but the document generated appears to have
some blank lines at the top that are causing problems.

If I connect directly to the URL, when I call the ".Read" method on
the XMLTextReader, I get the message:

"The XML declaration is unexpected. Line 8, Column 3"

If I open the URL in my browser and copy and paste the XML stuff
(starting with <?xml...) to a text file, save it locally and then
access that file using the XMLText Reader, all is well. It appears
as if a bunch (7, actually) of blank lines are prepended to the top
of the file from the web server so that they appear before the
<?xml... declaration.

Is this an an example of a non-well-formed document?
It should work, as far as I know.

Are you sure they're blank lines, and not HTTP headers? Headers would
confuse the hell out of an XmlReader, and would also indeed not show if

you copy/past the URL in a browser.

--
Sven Groot

http://unforgiven.bloghorn.com


Nov 20 '05 #3
Ryan S wrote:
If I open the URL in my browser and copy and paste the XML stuff (starting
with <?xml...) to a text file, save it locally and then access that file
using the XMLText Reader, all is well. It appears as if a bunch (7,
actually) of blank lines are prepended to the top of the file from the web
server so that they appear before the <?xml... declaration.

Is this an an example of a non-well-formed document?


Yep. In a well-formed XML document nothing (but unicode byte-order mark)
can precede XML declaration. It must be the very first thing in the
document.

--
Oleg Tkachenko [XML MVP]
http://blog.tkachenko.com
Nov 20 '05 #4
Thanks for everyone's help and comments. I solved my problem by reading the
HTTP stream and dumping it, starting with "<?xml", into a temp file which I
then call with DataSet.ReadXML on.

-Ryan
"Ryan S" <Ryan@somewhere > wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
I am trying to read an XML document generated by a web server using the
XMLTextReader class, but the document generated appears to have some blank
lines at the top that are causing problems.

If I connect directly to the URL, when I call the ".Read" method on the
XMLTextReader, I get the message:

"The XML declaration is unexpected. Line 8, Column 3"

If I open the URL in my browser and copy and paste the XML stuff (starting
with <?xml...) to a text file, save it locally and then access that file
using the XMLText Reader, all is well. It appears as if a bunch (7,
actually) of blank lines are prepended to the top of the file from the web
server so that they appear before the <?xml... declaration.

Is this an an example of a non-well-formed document?

Is there a way to have the XMLTextReader skip over these lines, or is there a way for me to intercept the stream and only start parsing at the
appropriate point?

Thanks,
Ryan

BTW, I am specifically trying to call the APIs from BMC's Patrol Express
product which return an XML document.

Nov 20 '05 #5

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

Similar topics

7
7075
by: John | last post by:
I have over 5000 thumbnail pictures of size 5kb each. I would like to able to load all 5000 pictures and view 50 per page using mysql_data_seek(). I would like to know what are the advantages and disadvantages of using a MySQL blob field rather than reading the images directly from the file? How does one insert an image into a blob field?...
0
1367
by: Row | last post by:
HI, I would first like to say its been about 3 years since looking at java im very rusty! I have to write a post it notes type applet which will function online. (reading from a flat text file) My main problem is: getting each paragraph into my vector array - so that each paragraph sits in a new array element. Eg: when i referance array...
6
20491
by: Eddie | last post by:
When I use JavaScript to read an element's textDecoration style, I only get one value even if there are more than one in the sytle sheet. For example if the text-decoration is defined as: text-decoration : underline overline; when reading element.currentStyle.textDecoration I only get "underline"!! What's worse is that...
1
1673
by: JackPhil | last post by:
I searched in the python-mode.el, sf.net, python.org, and found nothing Best regards
7
27720
by: bhanuprakash | last post by:
I am trying to use fscanf to read my test file. In my test file i sometimes have blank lines. When I try to read using the following format. fscanf(fp,"%\n",temp_str); If there is any blank line it reads contents from the next line. How do I read blank into my variable if the line is blank. Example
3
2155
by: bbepristis | last post by:
Hey all I have this code that reads from one text file writes to another unless im on a certian line then it writes the new data however it only seems to do about 40 lines then quits and I cant figure out why any help would be much apprechiated 1. Dim line_num As Integer 2. Dim filename2 As String 3.
1
1524
by: bbepristis | last post by:
Hey all I have a wired issue I have a csv file with , seperated values I have some code to read the file and put the record into an array then into textboxes. the problem is it seems to read everyother line of the file not everyline at first I thought it might be the code then the csv file The csv is a mysql generated via webmin however I cant...
25
5826
by: 7stud | last post by:
I can't break out of the for loop in this example: ------ import sys lst = for line in sys.stdin: lst.append(line) break
2
26670
by: jatindersingh80 | last post by:
Hi , i am reading a text file with token # but somtimes blank lines comes between the line at blank line the code gives exception of no such element the text files contains data after blank lines jatinder
0
7425
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7682
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7935
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7449
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6009
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5351
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3479
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3465
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1037
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.