XMLUtils.java
资源名称:Ajax.rar [点击查看]
上传用户:shjgzm
上传日期:2017-08-31
资源大小:2757k
文件大小:1k
源码类别:
Ajax
开发平台:
Java
- package ajax.util;
- public class XMLUtils {
- private static final char[] LT = "<".toCharArray();
- private static final char[] GT = ">".toCharArray();
- private static final char[] AMP = "&".toCharArray();
- private static final char[] QUOT = """.toCharArray();
- private static final char[] APOS = "'".toCharArray();
- public static String escapeXML(String text) {
- char[] textChars = text.toCharArray();
- StringBuffer sb = new StringBuffer();
- for (int i = 0; i < textChars.length; i++) {
- char c = textChars[i];
- switch (c) {
- case '<':
- sb.append(LT, 0, 4);
- break;
- case '>':
- sb.append(GT, 0, 4);
- break;
- case '&':
- sb.append(AMP, 0, 5);
- break;
- case '"':
- sb.append(QUOT, 0, 6);
- break;
- case ''':
- sb.append(APOS, 0, 6);
- break;
- default:
- sb.append(c);
- }
- }
- return sb.toString();
- }
- }