This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
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
Author

reproducing An invalid XML character (Unicode: 0x0)

Kaushik Baral
Greenhorn

Joined: Aug 08, 2009
Posts: 23
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
Ranch Hand

Joined: Aug 27, 2012
Posts: 1035
    
  10

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
Rancher

Joined: Mar 22, 2000
Posts: 12761
    
    5
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.

Bill
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

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.

 
 
subject: reproducing An invalid XML character (Unicode: 0x0)
 
Similar Threads
Invalid Character inside CDATA
An invalid XML character (Unicode: 0x0)
Removing tab character(^I) and null character Unicode: 0x0 from configuration XML file.
Exception
XML ERROR/hex representation of unicode 0x0