Saturday, April 11, 2015

How to fix org.apache.xmlbeans.XmlException: error: Unexpected character encountered (lex state 3)


I have encountred this error while trying to communicate with a webservice that returns in its XML a url containing a "&" character. While parsing the XML response my web server gives this error : "org.apache.xmlbeans.XmlException: error: Unexpected character encountered (lex state 3)".
The solution is to replace this character by "&" before parsing the XML response.

response = response.replaceAll("&", "& a m p ;"); 
That's all you need to do. It means that the xml document you're parsing isn't perfect.




No comments: