hexadecimal value 0x0B, is an invalid character issue in XML

前端 未结 1 1494
面向向阳花
面向向阳花 2021-01-12 03:17

I am getting exception

\'\', hexadecimal value 0x0B, is an invalid character. Line 23, position 22.

I have already tri

相关标签:
1条回答
  • 2021-01-12 03:56

    You can replace these invalid characters using the below method.

    public static string CleanInvalidXmlChars(this string StrInput)
        {
            //Returns same value if the value is empty.
            if (string.IsNullOrWhiteSpace(StrInput))
            {
                return StrInput;
            }
            // From xml spec valid chars:
            // #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF]    
            // any Unicode character, excluding the surrogate blocks, FFFE, and FFFF.
            string RegularExp = @"[^\x09\x0A\x0D\x20-\xD7FF\xE000-\xFFFD\x10000-x10FFFF]";
            return Regex.Replace(StrInput, RegularExp, String.Empty);
        }
    
    0 讨论(0)
提交回复
热议问题