Skip to content

Instantly share code, notes, and snippets.

@miceno
Created January 30, 2011 10:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save miceno/802781 to your computer and use it in GitHub Desktop.
Save miceno/802781 to your computer and use it in GitHub Desktop.
Groovy (java) escape HTML
import org.apache.commons.lang.StringEscapeUtils
// Alternate way to import
this.class.classLoader.rootLoader.addURL(new File("/usr/local/java/grails-1.0/lib/commons-lang-2.1.jar").toURL())
xml = '''
<module id="id" version="0.0.1" package="package"> </module>
'''
StringEscapeUtils.escapeHtml(xml).split("\n").each() {println it }
// Result will be
// &lt;module id=&quot;id&quot; version=&quot;0.0.1&quot; package=&quot;package&quot;&gt; &lt;/module&gt;
// Thanks to Alex Kotchnev's Blog: http://www.troymaxventures.com/2008/05/groovy-html-encode.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment