user1338410
user1338410

Reputation: 11

Decoding the Special characters retrieved from the XML file

This is regarding decoding the special characters from the XML file which is internally retrieved from the data base through parser. The partial data that we got is

"qutes", sigle quotes', namne? 

Here, the XML character ' " should be converted to plain quotes like ". In the similar way ''' which is a single quote(apostrophes). Is there any way to do this in JAVA. Kindly, let me know if you need any information.

Upvotes: 1

Views: 5212

Answers (4)

Roger F. Gay
Roger F. Gay

Reputation: 1971

You can used PrintWriter . println. You can also now use XPL to store data rather than XML. XPL is just like XML, but allows special characters in text elements.

Upvotes: 0

Puce
Puce

Reputation: 38152

Use:

http://docs.oracle.com/javase/7/docs/api/javax/xml/bind/DatatypeConverter.html#parseString%28java.lang.String%29

Also consider to use JAXB, which will do all the conversions for you.

Upvotes: 0

DonCallisto
DonCallisto

Reputation: 29932

Try this: StringEscapeUtils.unescapeHTML()

Unescapes a string containing entity escapes to a string containing the actual Unicode characters corresponding to the escapes. Supports HTML 4.0 entities. For example, the string "&lt;Fran&ccedil;ais&gt;" will become "<Français>" If an entity is unrecognized, it is left alone, and inserted verbatim into the result string. e.g. "&gt;&zzzz;x" will become ">&zzzz;x".

Upvotes: 1

barsju
barsju

Reputation: 4446

If you parse your XML with Stax or DOM this would be handled automatically. If not there is a duplicate thread here: How to decode encoded special XML characters in a string?

Upvotes: 2

Related Questions