C# hexadecimal value 0x12, is an invalid character

前端 未结 6 849
暗喜
暗喜 2020-12-25 10:48

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

6条回答
  •  情深已故
    2020-12-25 11:50

    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);
    

提交回复
热议问题