StringEscapeUtils.escapeXml


  • Unescapes a string containing XML entity escapes to a string containing the actual Unicode characters corresponding to the escapes.
  • Supports only the five basic XML entities (gt, lt, quot, amp, apos). Does not support DTDs or external entities.
  • Note that numerical \\u unicode codes are unescaped to their respective unicode characters. This may change in future releases.

  1.  package com.utilitySample;
  2.  import org.apache.commons.lang.StringUtils;

  3.  public class StringUtility {
  4.  public static void main(String[] args) {
  5.    String xmlString = "<data>";
  6.    System.out.println("After escapeXml::"+StringEscapeUtils.escapeXml(xmlString));
  7.    System.out.println("After unescapeXml::"+StringEscapeUtils.unescapeXml(xmlString));
  8. }
  9.  }

 Output :
 After escapeXml::&lt;data&gt;
 After unescapeXml::<data>

No comments:

Post a Comment