3

I am receiving the below mentioned error in my XSL: An invalid XML character (Unicode: 0x0) was found in the element content of the document.

Not very sure why I am getting it. I found some posts on the internet saying it's because of some NULL value, some said it's a problem with the parser. What does this error mean?

Unsigned
  • 9,640
  • 4
  • 43
  • 72
user2752800
  • 31
  • 1
  • 2

2 Answers2

2

The error message means exactly what it says: there is a "character" in your document with codepoint zero, and that isn't allowed by XML.

Why you are getting this error - that is, how this zero comes to be in your document - is something we have no hope of knowing from the information provided.

@sudhAnsu63 has suggested how you might repair the document to remove the offending characters. But repairing a bad document doesn't fix the problem: you need to chase data corruptions to their source and fix the process that created them in the first place.

Michael Kay
  • 156,231
  • 11
  • 92
  • 164
0

There are some characters that are not recognized by an xml parser. you need to replace/ handel these chracters. You can use the following extension method in C#/.Net to replace these chracters from your xml document prior to parsing.

public static string CleanInvalidXmlChars(this string 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);
}
sudhansu63
  • 6,025
  • 4
  • 39
  • 52