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(n ew WhiteSpaceTrimm ingStream(new FileStream(file name)));
Where
class WhiteSpaceTrimm ingReader : TextReader {
StreamReader file;
bool firstRead = true;
WhiteSpaceTrimm ingStream(Strea mReader file) {
this.file = file;
}
public override int Read(char[] buffer, int offset, int len) {
int found = 0;
while (found == 0) {
found = file.Read(buffe r, 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(buff er, i, buffer, 0, found - i);
found -= i;
}
}
}
return found;
}
// and delegate the rest of Stream API to underlying stream.
}
"prasad" <pr************ @net.pennywises olutions.com> wrote in message
news:%2******** ********@TK2MSF TNGP12.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******** ************@co mcast.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 interoperabilit y in .NET classes by enforcing
standards compliance (since interoperabilit y 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.pennywises olutions.com> wrote in message
news:%2******** ********@tk2msf tngp13.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.
>
>
>