Here you can find the source of xmlEncodeAttr(String src)
public static String xmlEncodeAttr(String src)
//package com.java2s; /*/* w w w . j a va 2s . c o m*/ * ==================================================================== * Copyright (c) 2004-2012 TMate Software Ltd. All rights reserved. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms * are also available at http://svnkit.com/license.html * If newer versions of this license are posted there, you may use a * newer version instead, at your option. * ==================================================================== */ public class Main { public static String xmlEncodeAttr(String src) { StringBuffer sb = new StringBuffer(src.length()); for (int i = 0; i < src.length(); i++) { char ch = src.charAt(i); switch (ch) { case '&': if (sb == null) { sb = createStringBuffer(src, i); } sb.append("&"); break; case '<': if (sb == null) { sb = createStringBuffer(src, i); } sb.append("<"); break; case '>': if (sb == null) { sb = createStringBuffer(src, i); } sb.append(">"); break; case '\'': if (sb == null) { sb = createStringBuffer(src, i); } sb.append("'"); break; case '\"': if (sb == null) { sb = createStringBuffer(src, i); } sb.append("""); break; case '\r': if (sb == null) { sb = createStringBuffer(src, i); } sb.append(" "); break; case '\n': if (sb == null) { sb = createStringBuffer(src, i); } sb.append(" "); break; case '\t': if (sb == null) { sb = createStringBuffer(src, i); } sb.append("	"); break; default: if (sb != null) { sb.append(ch); } } } return sb != null ? sb.toString() : src; } private static StringBuffer createStringBuffer(String src, int length) { StringBuffer sb = new StringBuffer(src.length()); sb.append(src.toCharArray(), 0, length); return sb; } }