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

Roger Keays is an artist, an engineer, and a student of life. He has no fixed address and has left footprints on 40-something different countries around the world. Roger is addicted to surfing. His other interests are music, psychology, languages, the proper use of semicolons, and finding good food.

Leave a Comment

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

Comment posted by: Ryan Lubke, 16 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: , 16 years ago

Mojarra 1.2.04_p02

Comment posted by: Ryan Lubke, 16 years ago

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