What are invalid characters in XML

后端 未结 15 1272
时光说笑
时光说笑 2020-11-22 03:23

I am working with some XML that holds strings like:

This is a string

Some of the strings that I am passing to the

15条回答
  •  你的背包
    2020-11-22 04:18

    This is a C# code to remove the XML invalid characters from a string and return a new valid string.

    public static string CleanInvalidXmlChars(string text) 
    { 
        // 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 re = @"[^\x09\x0A\x0D\x20-\uD7FF\uE000-\uFFFD\u10000-\u10FFFF]"; 
        return Regex.Replace(text, re, ""); 
    }
    

提交回复
热议问题