jQuery in Action, 3rd edition
The moose likes XML and Related Technologies and the fly likes reproducing An invalid XML character (Unicode: 0x0) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "reproducing An invalid XML character (Unicode: 0x0)" Watch "reproducing An invalid XML character (Unicode: 0x0)" New topic

reproducing An invalid XML character (Unicode: 0x0)

Kaushik Baral

Joined: Aug 08, 2009
Posts: 27
Hi All,

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 internet saying its because of some NULL value, some said its problem with the parser. but i want to know the actual problem and from where its coming. i have received this error in my prod. environment and i am trying to reproduce the issue but not able to do the same. could some one please tell me how can i get the same error again.

thanks a lot in advance.
Richard Tookey

Joined: Aug 27, 2012
Posts: 1166

If the XML is UTF-32BE or UTF-32LE encoded and includes a BOM then it could account for the problem since UTF-32BE has a BOM of 0x00, 0x00, 0xFE, 0xFF and UTF-32LE has a BOM of 0xFF, 0xFE, 0x00, 0x00. You need to use a HEX editor on the offending file content to see exactly where the character code of zero appears.
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 13037
Parsing the source as an XML document should cause a SAXParseException. Catch that and you can extract the line and column number from the parse exception.

Most of my illegal character problems have been due to text edited with MS Word - especially those "smart punctuation" characters.

I use UltraEdit-32 for fiddling with hex characters - not free but very very useful. You could use a hex editor to insert any character you want.

Paul Clapham

Joined: Oct 14, 2005
Posts: 19973

As for how to reproduce the issue: since the problem is that the XML document you tried to parse contains a character which isn't valid according to the rules of XML, you should just try to parse that same document over again.

I agree. Here's the link: http://aspose.com/file-tools
subject: reproducing An invalid XML character (Unicode: 0x0)
It's not a secret anymore!