Java代码  
  1. import java.util.ArrayList;   
  2. import java.util.List;   
  3. import java.util.regex.Matcher;   
  4. import java.util.regex.Pattern;   
  5.   
  6.   
  7. public class XmlTomcatUtil {   
  8.   
  9.     // 系统日志类   
  10.         private static SystemLog systemLog = new SystemLog(XmlTomcatUtil.class);   
  11.     
  12.     /**  
  13.      * 替换获得的结果中的所有注释  
  14.      * 例如   
  15.      * 输入  
  16.      *   
  17.      *   
  18.      * 输出  
  19.      *   
  20.      *   
  21.      * @param str 输入字符串  
  22.      * @return  
  23.      */  
  24.     public static String getRegex(String str){   
  25.            
  26.         try {   
  27.                
  28.              Pattern p = Pattern.compile("",Pattern.DOTALL);   
  29.              Matcher matcher = p.matcher(str);    
  30.              List strList = new ArrayList();   
  31.                
  32.              //记录发现的错误结果值   
  33.              while (matcher.find()) {   
  34.                  strList.add(matcher.group());   
  35.              }   
  36.                 
  37.              for (String arg : strList) {   
  38.                 str = str.replaceAll(arg, "");   
  39.              }   
  40.                
  41.         } catch (Exception e) {   
  42.             systemLog.error("XmlUtil.getRegex""替换所有的注释字符", e);   
  43.         }   
  44.         return str;   
  45.     }   
  46. }