Here you can find the source of toXMLString(String in)
Parameter | Description |
---|---|
in | non-null input string |
public static String toXMLString(String in)
//package com.java2s; //License from project: Apache License public class Main { /**/*from www . ja va 2s.c om*/ Do character conversions to convert a string to an XML parsable string @param in non-null input string @return non-null return string */ public static String toXMLString(String in) { StringBuffer sb = new StringBuffer(in.length() + 100); // boolean inQuote = false; for (int i = 0; i < in.length(); i++) { char c = in.charAt(i); switch (c) { case '\"': sb.append("""); break; case '&': sb.append("&"); break; case '\'': sb.append("'"); case '<': sb.append("<"); break; case '>': sb.append(">"); break; default: sb.append((char) c); } } return (sb.toString()); } }