tags:

views:

270

answers:

2

I have Finnish characters in my text (for example ä, ö and å) that are unsafe in XML, is there any library/framwork for this purpose?

+1  A: 

StringEscapeUtils from Commons Lang has the escapeXML method which will suit your needs.

Valentin Rocher
+2  A: 

XML supports Unicode, so the only thing you really need to escape are the five basic XML entities (gt, lt, quot, amp, apos). If you use StringEscapeUtils.escapeXML, it will turn all your ä, ö and å into ugly \uabcd stuff.

Thilo
Incidentally, there are some characters that the XML spec treats as illegal, no matter how you try to encode them. The ASCII NUL character for example.
Stephen C