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.
>
>
>