I am loading a lot of xml documents and some of them return errors like \"hexadecimal value 0x12, is an invalid character\" and there are different character. How to remove
I think x26 "&" is a valid character and it could be de-serialized by XML.
So to replace illegal character, we should use:
// Replace illegal character in XML documents with blank
// See here for reference http://www.w3.org/TR/xml/#charsets
var regex = "[\x00-\x08\x0B\x0C\x0E-\x1F]";
xml = Regex.Replace(xml, r, String.Empty, RegexOptions.Compiled);