No need to add any third party libraries to your application. Simply use Tomcat’s one. Remember to always check your string for invalid characters before parsing it into xml.

import org.apache.jasper.xmlparser.XMLChar;
StringBuilder sb = new StringBuilder();
for (int i = 0; i < xmlstring.length(); i++) {
  char c = xmlstring.charAt(i);
    if (XMLChar.isValid(c)) {
      sb.append(c);
  }
}
 
xmlstring = sb.toString();

 

Dima Svirid

Software architect, JAVA, Spring, Hibernate, AngularJs, Backbone, MongoDB, Oracle. CTO and Co-Founder of Homeadnet.com

More Posts

Follow Me:

Tagged with: