473,386 Members | 1,720 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,386 software developers and data experts.

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 3203
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**************@TK2MSFTNGP10.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****************@TK2MSFTNGP12.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
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...
0
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)...
6
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:...
1
by: JackPhil | last post by:
I searched in the python-mode.el, sf.net, python.org, and found nothing Best regards
7
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...
3
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...
1
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...
25
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
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...

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.