Thursday, June 9, 2011

Escape XML Using Apache Commons Lang - StringEscapeUtils

Apache Commons Lang has many tools to facilitate the Java Programmer to build a program. If you want to escape XML, Apache has StringEscapeUtils class to do so. For example:


    private String convert(String source) {
        String result = StringEscapeUtils.escapeXml(source);
        return result;
    } 


StringEscapeUtils have many methods to perform many activities of escape, such as XML, HTML, Java and others.