I'm trying to deserialize a xml response from a Rest service. I'm implementing IXmlSerializable because the xml is rather specific and I do custom serializing. The response contains illegal xml characters but as I have no way to modify the xml I'll have to deal with them.
The solution seems simple : when creating my XmlReader I feed it XmlSetting with ChecCharacters set to false :
XmlReaderSettings settings = new XmlReaderSettings();
settings.CheckCharacters = false;
using (var reader = XmlReader.Create(filename, settings))
{
var xRoot = new XmlRootAttribute(RootElement);
var serializer = new XmlSerializer(typeof(T), xRoot);
return (T)serializer.Deserialize(reader);
}
When checking the CheckCharacters is effectively set to false.
But I still keep getting errors like :
{"'', hexadecimal value 0x01, is an invalid character. Line 9, position 55."}
I thought the CheckCharacters=false setting was intended to avoid throwing errors because of illegal Xml characters ?
Any idea where I make a mistake, why the errors keep on being thrown ?
thnx in advance.. Raf
From MSDN:
So setting
CheckCharacters
tofalse
won't allow to you parse invalid XML.You can try to replace binary characters with escapes:
'\x01'
with""
etc.XmlReader
with disabledCheckCharacters
seems to accept those.