PROBLEM

I have a question regarding taking properties from an EJB and generating XML
output. To explain, here is an example of my problem:

<poem title = "<%= myPoem.getTitle()">   <%= myPoem.getContents() %>
</poem>

Because title is an XML attribute I think special characters like '&' needs
to be escaped with &amp; and the like. How does one handle this in a nice
way?





BACKGROUND

I can think of at least two solutions, but I was hoping someone could
suggest a better one:

1: One could make sure to always store all content in the database as
escaped content. This means that the title of myPoem could be stored as
"Strength &amp; Honour" instead of "Strength & Honour".

2: One could require all get/set-methods to transform unescaped content to
escaped content and vise-versa.

3: One could use a utility class with a static method:
<poem title = "<%= Converter.convert(myPoem.getTitle()) %>"> .....


I know all this could work, but still I think it involves a programming
overhead which I would like to avoid if possible. - Especially because I
have found out I do not need to do any conversion for content which is not
used in an attribute, e.g. myPoem.getContents() works fine no matter what it
contains.


Reply via email to