十六进制值0x0B中,在XML中是无效字符的问题 [英] hexadecimal value 0x0B, is an invalid character issue in XML

查看:1587
本文介绍了十六进制值0x0B中,在XML中是无效字符的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


  我得到异常'',十六进制值0x0B中,是一个无效字符。第23行,第22位。

I am getting exception '', hexadecimal value 0x0B, is an invalid character. Line 23, position 22.

我已经尝试从<解决方案href=\"http://stackoverflow.com/questions/20762/how-do-you-remove-invalid-hexadecimal-characters-from-an-xml-based-data-source-p\">Here,但它不是为我工作。由于我的项目是在 3.5 版,我不能用XmlConvert.IsXmlChar方法的 MSDN

I have already tried solution from Here, but it is not working for me. As my project is in 3.5 version, I cannot use XmlConvert.IsXmlChar method MSDN

该如何处理呢?

推荐答案

您可以使用下面的方法替换这些无效字符。

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

这篇关于十六进制值0x0B中,在XML中是无效字符的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆