Skip to content

Instantly share code, notes, and snippets.

@dsummersl
Forked from miceno/gist:802781
Created November 8, 2012 21:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dsummersl/4041911 to your computer and use it in GitHub Desktop.
Save dsummersl/4041911 to your computer and use it in GitHub Desktop.
Groovy (java) escape HTML with grapes
import org.apache.commons.lang.StringEscapeUtils
// Import with groovy grapes:
@Grab(group='commons-lang', module='commons-lang', version='2.3' )
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