Java examples for XML:XML String Escape
escape XML String by replace
//package com.java2s; public class Main { public static void main(String[] argv) throws Exception { String s = "java2s.com"; System.out.println(escape(s)); }/*from w ww . java2s . c o m*/ public static String escape(String s) { if (s == null) { return s; } return s.replaceAll("&", "&").replaceAll("<", "<") .replaceAll(">", ">").replaceAll("'", "'") .replaceAll("\"", """); } }