Escaping XML in XML in JSF

By , 14 June 2008

Escaping XML in XML in JSF

Recently I discovered that my RSS feeds were broken because of the Latin characters in the content. JSF's h:outputText unhelpfully converts these to HTML entities which are invalid in XML files such as RSS feeds. Even with escape="false", the HTML markup still breaks the feed. Short of writing an XML renderer for h:outputText, I came up with the following putrid hack. It is an ugly stain on my otherwise beautiful code, a parasite to perfection, a car wreck on the corner of Coro Drive and Moggill Road, a pile of puppy poo on the pavement. But it works...

<title>
  <h:outputText value="&lt;![CDATA[" escape="false"/>
  <h:outputText value="${item.title}" escape="false"/>
  <h:outputText value="]]&gt;" escape="false"/>
</title>

Repeat for all output in your XML/RSS templates.

Escaping XML in XML in JSF

About Roger Keays

Escaping XML in XML in JSF

I guess I'd call myself a problem solver. Either that, or I'm some sort of organic machine designed to convert oxygen into carbon dioxide. You could go either way on that. I'm into languages and stuff. I wrote a book. It's okay, I guess. What else? I like reading, swimming, eating, and playing music. Satisfied? Sheesh.

Leave a Comment

Please visit https://rogerkeays.com/blog/escaping-xml-in-xml-in-jsf to add your comments.

Comment posted by: Ryan Lubke, 9 years ago

Might give 1.2_09 a shot.  We added a config parameter called com.sun.faces.disableUnicodeEscaping which may resolve this issue.

See the release notes [1] for details. 

[1] http://tinyurl.com/5txnpo

Comment posted by: , 9 years ago

Mojarra 1.2.04_p02

Comment posted by: Ryan Lubke, 9 years ago

I'm curious, which impl/version of JSF were you using when you hit this issue?