472,972 Members | 2,217 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,972 software developers and data experts.

Problem with XMLTextReader

Hi,
I am using XMLTextReader class to read the xml files.
In some cases xml declaration tag might start after space/tab charecters.
These kind of files are supported by the browsers and xml dom's
but the xmltextreader's are not supporting to read this kind of files.

Using XMLTextReaders is there anyway to read this kind of files.

Thanks in advance,
Prasad Dannani.

Nov 12 '05 #1
3 1641
Yes, it turns out that spaces before the xml declaration is not fully
standards compliant, so you XML would not have worked across other platforms
and we opted to go for best interoperability in .NET classes by enforcing
standards compliance (since interoperability is what XML is all about).

You could preload the file into a string and Trim the spaces then pass the
result via StringReader to XmlReader or you could provide a more efficient
solution by wrapping FileStream with your own clever Stream class that
strips initial whitespace.

"prasad" <pr************@net.pennywisesolutions.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Hi,
I am using XMLTextReader class to read the xml files.
In some cases xml declaration tag might start after space/tab charecters.
These kind of files are supported by the browsers and xml dom's
but the xmltextreader's are not supporting to read this kind of files.

Using XMLTextReaders is there anyway to read this kind of files.

Thanks in advance,
Prasad Dannani.

Nov 12 '05 #2
In mycase, i have to use XMLTextReader because of its advantages. But if i
use filestreams and load the complete info to a string and then using
xmlreader classes to read the values then its a double work with out any
advantage.

Anyway thanks for helping. can anyone please suggest me that is there any
property or class to help me which will support all the advantages of
xmltextreaders
"Chris Lovett" <so*****@nospam.please> wrote in message
news:yp********************@comcast.com...
Yes, it turns out that spaces before the xml declaration is not fully
standards compliant, so you XML would not have worked across other platforms and we opted to go for best interoperability in .NET classes by enforcing
standards compliance (since interoperability is what XML is all about).

You could preload the file into a string and Trim the spaces then pass the
result via StringReader to XmlReader or you could provide a more efficient
solution by wrapping FileStream with your own clever Stream class that
strips initial whitespace.

"prasad" <pr************@net.pennywisesolutions.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Hi,
I am using XMLTextReader class to read the xml files.
In some cases xml declaration tag might start after space/tab charecters. These kind of files are supported by the browsers and xml dom's
but the xmltextreader's are not supporting to read this kind of files.

Using XMLTextReaders is there anyway to read this kind of files.

Thanks in advance,
Prasad Dannani.


Nov 12 '05 #3
There is no way to tell XmlTextReader to ignore the whitespace.

My suggestion of passing a wrapper Stream to XmlTextReader does require
double copy of read buffers, but other than it is pretty efficient.

new XmlTextReader(new WhiteSpaceTrimmingStream(new FileStream(filename)));

Where

class WhiteSpaceTrimmingReader : TextReader {
StreamReader file;
bool firstRead = true;

WhiteSpaceTrimmingStream(StreamReader file) {
this.file = file;
}

public override int Read(char[] buffer, int offset, int len) {
int found = 0;
while (found == 0) {
found = file.Read(buffer, offset, len);
if (firstRead) {
int i = 0;
while (i < found) {
char ch = buffer[i];
if (ch != ' ' && ch != '\t' && ch != '\r' && ch != '\n')
{
break;
}
}
if (i > 0) {
Array.Copy(buffer, i, buffer, 0, found - i);
found -= i;
}
}
}
return found;
}

// and delegate the rest of Stream API to underlying stream.
}
"prasad" <pr************@net.pennywisesolutions.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
In mycase, i have to use XMLTextReader because of its advantages. But if i
use filestreams and load the complete info to a string and then using
xmlreader classes to read the values then its a double work with out any
advantage.

Anyway thanks for helping. can anyone please suggest me that is there any
property or class to help me which will support all the advantages of
xmltextreaders
"Chris Lovett" <so*****@nospam.please> wrote in message
news:yp********************@comcast.com...
Yes, it turns out that spaces before the xml declaration is not fully
standards compliant, so you XML would not have worked across other

platforms
and we opted to go for best interoperability in .NET classes by enforcing
standards compliance (since interoperability is what XML is all about).

You could preload the file into a string and Trim the spaces then pass
the
result via StringReader to XmlReader or you could provide a more
efficient
solution by wrapping FileStream with your own clever Stream class that
strips initial whitespace.

"prasad" <pr************@net.pennywisesolutions.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
> Hi,
> I am using XMLTextReader class to read the xml files.
> In some cases xml declaration tag might start after space/tab charecters. > These kind of files are supported by the browsers and xml dom's
> but the xmltextreader's are not supporting to read this kind of files.
>
> Using XMLTextReaders is there anyway to read this kind of files.
>
> Thanks in advance,
> Prasad Dannani.
>
>
>



Nov 12 '05 #4

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

Similar topics

3
by: Fede | last post by:
Hi to all, I've written a simple XML file and I'm trying to validate it using XMLValidatingReader and ValidationEventHandler event. This is my code: Imports System.Xml Imports...
3
by: Pete | last post by:
I'm trying to read an XML document and write out a slightly modified version using the XmlTextWriter. I'm basically trying to copy all the nodes exactly as they are read and do some text...
2
by: Joris Janssens | last post by:
I'm trying to write a program for validating XHTML 1.1-documents against the XHTML 1.1 DTD (which is actually the same as validating an XML-file) but I always get a "(404) Not found" error. This...
3
by: Keith | last post by:
Anyone else experience this problem when using the XmlTextReader? (See stack trace below) I've installed the patch from knowledge base article 839588, but it didn't fix it. ...
4
by: badbetty | last post by:
Hello and thank you for reading on (hopefully). How does one typecast the XMLREADER returned from the XSLTRANSFORM method 'transform' into XMLTEXTREADER, so it can be passed in to an...
1
by: Borgbjerg | last post by:
I've got a multi-threaded server (we are very early in the project, trying to uncover some risks), and I want to send data using XML. The class ServerAdapter is supposed to connect to the server...
1
by: Calvin X | last post by:
Hi All, I am getting the following error when I try to open an xml file that is in a directory just underneath the site root. 'Could not find a part of the path...
4
by: Paul Bromley | last post by:
I thought that XMLTextReader would be simple to use, but I have run into problems with it! I seem to have great difficulty extrcting the text of specific elements from a very simple XML file. I...
0
by: davidpenty | last post by:
Hi there, I am having some problems with a multi-threaded asp.net seach page. My search page sends off four asynchronous http requests to four search engines then waits for the results to come...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
3
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.