title: How to sanitize HTML code in Java to prevent XSS attacks?
body: <p>I'm looking for class/util etc. to sanitize HTML code i.e. remove dangerous tags, attributes and values to avoid XSS and similar attacks.</p>
  
  <p>I get html code from rich text editor (e.g. TinyMCE) but it can be send malicious way around, ommiting TinyMCE validation ("Data submitted form off-site").</p>
  
  <p>Is there anything as simple to use as InputFilter in PHP? Perfect solution I can imagine works like that (assume sanitizer is encapsulated in HtmlSanitizer class):</p>
  
  <pre><code>String unsanitized = "...&lt;...&gt;...";           // some potentially 
                                                // dangerous html here on input
  
  HtmlSanitizer sat = new HtmlSanitizer();      // sanitizer util class created
  
  String sanitized = sat.sanitize(unsanitized); // voila - sanitized is safe...
  </code></pre>
  
  <hr>
  
  <p><strong>Update</strong> - the simpler solution, the better! Small util class with as little external dependencies on other libraries/frameworks as possible - would be best for me.</p>
  
  <hr>
  
  <p>How about that?</p>