Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

xml

asp.net

enter image description here

I am getting exception

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

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

How to handle it ?

like image 956
user1926138 Avatar asked Mar 27 '15 12:03

user1926138


People also ask

What is hexadecimal value 0x02?

XmlException hexadecimal value 0x02, is an invalid character.. its, pointing to this line: var result = from x in XDocument.


1 Answers

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);
    }
like image 128
sudhAnsu63 Avatar answered Oct 06 '22 00:10

sudhAnsu63