locked
invalid XML characters RRS feed

  • Question

  • User-352166405 posted

    Hello, with the attached code, I'm getting the following error:

    hexadecimal value 0x0b, is an invalid character

    I have tried using Regex.Replace on an element like so:

    new XElement(Constants.XML_PROJECT_NAME, Regex.Replace(Common.GetReaderValue<string>(reader, Constants.DB_PROJECT_NAME), @"[\u0000-\u0008,\u000B,\u000C,\u000E-\u001F]", "") ?? null),

                 

    But, that gives me the following error:

    Value cannot be null Parameter name: input

    What would be the best way to strip out or handle those invalid characters or what am I doing wrong with the replace method?

     public static XDocument CreateCaseXDocument(SqlDataReader reader)
            {
                XDeclaration xDeclaration = new XDeclaration("1.0", "utf-8", "No");
    
                XElement[] xSubjects = CreateSubjects(reader);
             
    
                XDocument doc = new XDocument(xDeclaration,
                   new XElement(Constants.XML_PROJECT_NAME, Common.GetReaderValue<string>(reader, Constants.DB_PROJECT_NAME) ?? null);
                    
                return doc;
            }

    Thursday, August 13, 2015 10:18 AM

Answers

All replies