views:

84

answers:

2

I'm trying to add some text to a web app via a java .properties file. I want the text to have an en-dash in it. If I add the character entity, thus:

myProp=Foo – Bar

or

myProp=Foo – Bar

I get the code in my output. If I add the literal character to the properties file (and save as UTF-8):

mProp=Foo – Bar

I get the literal character in the output. How do I add the character entity to the output??

A: 

The first one is a HTML entity and the second one is a XML entity. So to get the first one displayed as a dash, it should be displayed unescaped by a HTML file and to get the second one displayed as a dash, it should be displayed unescaped by a XML file. Also, the files should be displayed using a proper tool, which can in this case be a webbrowser.

Are you displaying it unescaped in a HTML/XML file using a proper tool?

To determine whether it's escaped or unescaped, rightclick the page in webbrowser, choose View Source and you should check if the first ampersand is not being escaped as &amp; which would end up like &amp;ndash; or &amp;#8211; respectively. How to avoid escaping depends on the view technology you're using to display it. If it's for example JSP/JSTL <c:out>, then you should set the escapeXml="false" attribute.

BalusC
+1  A: 
erickson
This doesn't explain how he gets the literal character in the output for the literal dash.
BalusC