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="<![CDATA[" escape="false"/> <h:outputText value="${item.title}" escape="false"/> <h:outputText value="]]>" escape="false"/> </title>
Repeat for all output in your XML/RSS templates.
Escaping XML in XML in JSFRoger 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. |