Encoding For XHTML

Hi,

I am currently taking content out of a database to be displayed on a page in an XHTML format. However, the content I am receiving is a mixture of encoded and unencoded eg I sometimes get & and other times I get & within strings. This will typically be in a url. I wondered if anyone has already written a utility class for this. I had a look at XMLEncoder but it wasn't really that helpful.

Thanks in advance.

[441 byte] By [njmitchella] at [2007-10-2 21:44:42]
# 1

First you ought to get your terminology right. "Encoding" can refer to URL-encoding -- where $ is replaced by %24, for example, in a parameter of a URL. It can also refer to charsets like UTF-8 and windows-1252 which are used to convert Unicode chars to bytes. However "Escaping" refers to the requirement to represent the "&" character as "&" in text nodes in XML documents.

It appears you are asking if there is a method that automatically escapes text so that it can appear correctly in XML text nodes. There's no standard Java method to do that. Some JSTL tags will do it for you. Probably somebody at Apache has done it in one of their projects.

And if you're asking if there's a method that can determine if it has already been done, I don't think such a method could exist. If you can't tell if escaping has been done, you will have to do it anyway and too bad if it was done twice.

DrClapa at 2007-7-14 1:00:12 > top of Java-index,Other Topics,Algorithms...