I think, therefore I blog

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...

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

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. Since he left Australia in 2009, he has been living as a digital nomad in over 40 different countries around the world. Roger is addicted to surfing. His other interests are music, psychology, languages, and finding good food. Click here to subscribe to his weekly blog, or stalk him on Facebook and Twitter.

Leave a Comment

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

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

Mojarra 1.2.04_p02

Comment posted by: Ryan Lubke, 8 years ago

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

Join Over 1000 Subscribers

I write every Sunday about travel, psychology, and technology. Thousands of people just like you have already subscribed—and for good reason. It'll change your life. And it's free :)

Read a Good Book

“A spellbinding true story of love, passion and adventure. One can’t help but be swept away by 100% Love Guaranteed.” —Dr Tammie Matson, author of Elephant Dance.

Chat For A While

Your Vote Matters

Which animal will take over when humans go extinct?