i have following code:
public class TestStreamReader : StreamReader
{
.
.
public override int Read([In, Out] char[] buffer, int index, int count)
{
char[] charBuffer = new char[buffer.Length];
int i = base.Read(charBuffer, index, count);
string s = new string(charBuffer);
s = s.CleanInvalidXmlChars();
Buffer.BlockCopy(s.ToCharArray(), index, buffer, index, count);
return i;
}
}
But if I make following call:
XmlReaderSettings settings = new XmlReaderSettings
{
DtdProcessing = DtdProcessing.Ignore
};
using ( DataSet ds = new DataSet() ) {
using ( TestStreamReader stream = new TestStreamReader(fileName) ) {
using ( XmlReader tr = XmlReader.Create(stream, settings) ) {
ds.ReadXml(tr);
ImportDataSet(ds);
}
}
}
public static string CleanInvalidXmlChars(this string input)
{
if ( string.IsNullOrWhiteSpace(input) ) {
return input;
}
return input.Replace(" ", " ");
}
I get an exception:
The 'Description' start tag on line 53 position 6 does not match the end tag of 'Descrip'. Line 53, position 156. at System.Xml.XmlTextReaderImpl.Throw(Exception e) at System.Xml.XmlTextReaderImpl.ThrowTagMismatch(NodeData startTag) at System.Xml.XmlTextReaderImpl.ParseEndElement() at System.Xml.XmlTextReaderImpl.ParseElementContent()
The reason for the exception is that the Read is called only one time at the beginning and never more for loading next chunks of data.
Can anybody explain why does this happen?