Parsing an xml file on Java I get the error:
An invalid XML character (Unicode: 0x0) was found in the element content of the document.
The xml comes from a webservice.
The problem is that I get the error only when the webservice is running on localhost (windows+tomcat), but not when the webservice is online (linux+tomcat).
How can I replace the invalid char?? Thanks.
This is an encoding issue. Either you read it the inputstream as UTF8 and it isn't or the other way around.
You should specify the encoding explicitly when you read the content. E.g. via
Another problem could be the tomcat. Try to add URIEncoding="UTF-8" in your tomcat’s connector settings in the server.xml file. Because:
Taken from here.
Unicode character
0x0
representsNULL
meaning that the data you're pulling contains a NULL somewhere (which is not allowed in XML and hence your error).Make sure that you find out what causes the NULL in the first place.
Also, how are you interacting with the WebService? If you're using Axis, make sure that the WSDL has some encoding specified for data in and out.
fixed with this code:
A bit of looking around reveals that 0x0 is a null character, someone else had the same problem with XML and null characters here http://forums.sun.com/thread.jspa?threadID=579849. Not sure how you are parsing the XML but if you get it as a string first there is some discusion on how to replace the null here http://forums.sun.com/thread.jspa?threadID=628189.