Escape un escape Xml : Xml « Development « Android






Escape un escape Xml

     

class Main{

  public static String escapeXMLChars(String s) {
    return s.replaceAll("&",  "&")
         .replaceAll("'",  "'")
         .replaceAll("\"", """)
         .replaceAll("<",  "&lt;")
         .replaceAll(">",  "&gt;");
  }
  
  public static String unescapeXMLChars(String s) {
    return s.replaceAll("&amp;",  "&")
         .replaceAll("&apos;", "'")
         .replaceAll("&quot;", "\"")
         .replaceAll("&lt;",   "<")
         .replaceAll("&gt;",   ">");
  }
}

   
    
    
    
    
  








Related examples in the same category

1.Using xml resource
2.XML Resource Demo
3.Load style from styles.xml
4.Define PreferenceScreen in xml file
5.Using XML Parser
6.XML-defined adapters can be used to easily create adapters in your own application or to pass adapters to other processes.
7.Xml Parse
8.Xml Serializer Uri
9.Get Text Content from Xml Node
10.Get Xml node value with substring
11.Get value from Element
12.Get attribute value
13.Get field from NamedNodeMap
14.get Node Value With Attribute
15.get Character Data From Element
16.update Xml