Instead of including a large library just for escaping xml, using this util.
it should be used in very rare cases because the server should not return xml format message
@param nonEscapedXmlStr
434381
private static String escapeXml (String nonEscapedXmlStr) {
        StringBuilder escapedXML = new StringBuilder();
        for (int i = 0; i < nonEscapedXmlStr.length(); i++) {
            char c = nonEscapedXmlStr.charAt(i);
            switch (c) {
                case '<':
                    escapedXML.append("&lt;");
                    break;
                case '>':
                    escapedXML.append("&gt;");
                    break;
                case '\"':
                    escapedXML.append("&quot;");
                    break;
                case '&':
                    escapedXML.append("&amp;");
                    break;
                case '\'':
                    escapedXML.append("&apos;");
                    break;
                default:
                    if (c > 0x7e) {
                        escapedXML.append("&#" + ((int) c) + ";");
                    } else {
                        escapedXML.append(c);
                    }
            }
        }
        return escapedXML.toString();
    }
215926
function escapeXml (string) {
    return String(string).replace(/"/g, '&quot;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
  }
18526
public static void objectToXML(Object object, String fileName) throws FileNotFoundException {
		FileOutputStream fo = new FileOutputStream(fileName);
		XMLEncoder encoder = new XMLEncoder(fo);
		encoder.writeObject(object);
		encoder.close();
	}
1155315
public static String escapeXML(final String s) {
        final char[] chars = s.toCharArray();
        return escapeXML(chars, 0, chars.length);
    }
1309008
public static String encodeXmlAttribute(String str) {
    if (str == null) return null;
    int len = str.length();
    if (len == 0) return str;
    StringBuffer encoded = new StringBuffer();
    for (int i = 0; i < len; i++) {
      char c = str.charAt(i);
      if (c == '<') encoded.append("&lt;");
      else if (c == '\"') encoded.append("&quot;");
      else if (c == '>') encoded.append("&gt;");
      else if (c == '\'') encoded.append("&apos;");
      else if (c == '&') encoded.append("&amp;");
      else encoded.append(c);
    }
    return encoded.toString();
  }
687868
private String  textXMLSpaceTransform(String text, boolean isFirstChild, boolean isLastChild)
   {
      if (state.spacePreserve)  // xml:space = "preserve"
         return text.replaceAll("[\\n\\t]", " ");

      // xml:space = "default"
      text = text.replaceAll("\\n", "");
      text = text.replaceAll("\\t", " ");
      //text = text.trim();
      if (isFirstChild)
         text = text.replaceAll("^\\s+",  "");
      if (isLastChild)
         text = text.replaceAll("\\s+$",  "");
      return text.replaceAll("\\s{2,}", " ");
   }
939310
public static <T> T readObjectFromXml(String xmlStr) throws IOException {
		return readObjectFromXml(new InputSource(StrUtil.getReader(xmlStr)));
	}
1323640
static String toXmlString(Node node) {
        try {
            Transformer transformer = getTF().newTransformer();
            transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
            transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
            transformer.setOutputProperty(OutputKeys.INDENT, "no");
            StringWriter sw = new StringWriter();
            StreamResult result = new StreamResult(sw);
            DOMSource source = new DOMSource(node);
            transformer.transform(source, result);
            return sw.toString();
        } catch (Exception e) {
            throw wrap(e);
        }
    }
969132
private Integer getNonSpecialAttrLength(NamedNodeMap attributes) {
        int length = 0, maxLength = attributes.getLength();
        for (int i = 0; i < maxLength; ++i) {
            Attr a = (Attr) attributes.item(i);
            if (!isXMLNSAttribute(a)
                && !isRecognizedXMLSchemaInstanceAttribute(a)) {
                ++length;
            }
        }
        return new Integer(length);
    }
520531
private String generateXml(String encrypt, String signature, String timestamp, String nonce) {
    String format =
        "<xml>\n"
            + "<Encrypt><![CDATA[%1$s]]></Encrypt>\n"
            + "<MsgSignature><![CDATA[%2$s]]></MsgSignature>\n"
            + "<TimeStamp>%3$s</TimeStamp>\n"
            + "<Nonce><![CDATA[%4$s]]></Nonce>\n"
            + "</xml>";
    return String.format(format, encrypt, signature, timestamp, nonce);
  }
822269
private static String escapeXml(final String text, final XmlEscapeSymbols symbols,
                                    final XmlEscapeType type, final XmlEscapeLevel level) {

        if (type == null) {
            throw new IllegalArgumentException("The 'type' argument cannot be null");
        }

        if (level == null) {
            throw new IllegalArgumentException("The 'level' argument cannot be null");
        }

        return XmlEscapeUtil.escape(text, symbols, type, level);

    }
661596
private String escapeForPOFile(final String input, boolean fix) {
        if (input == null) return "";

        String escapedString = input;

        // Publican escapes greater/lesser than to XML entities
        if (fix && (input.contains(" < ") || input.contains(" > "))) {
            // Loop over and find all the XML Elements as they should remain untouched.
            final LinkedList<String> elements = new LinkedList<String>();
            if (input.indexOf('<') != -1) {
                int index = -1;
                while ((index = input.indexOf('<', index + 1)) != -1) {
                    int endIndex = input.indexOf('>', index);
                    int nextIndex = input.indexOf('<', index + 1);

                    /*
                      * If the next opening tag is less than the next ending tag, than the current opening tag isn't a match for the next
                      * ending tag, so continue to the next one
                      */
                    if (endIndex == -1 || (nextIndex != -1 && nextIndex < endIndex)) {
                        continue;
                    } else if (index + 1 == endIndex) {
                        // This is a <> sequence, so it should be ignored as well.
                        continue;
                    } else {
                        elements.add(input.substring(index, endIndex + 1));
                    }

                }
            }

            // Find all the elements and replace them with a marker
            for (int count = 0; count < elements.size(); count++) {
                escapedString = escapedString.replace(elements.get(count), "###" + count + "###");
            }

            // Perform the replacements on what's left
            escapedString = escapedString.replace("<", "&lt;").replace(">", "&gt;");

            // Replace the markers
            for (int count = 0; count < elements.size(); count++) {
                escapedString = escapedString.replace("###" + count + "###", elements.get(count));
            }
        }

        return escapedString.replace("\\", "\\\\")
                .replace("\"", "\\\"")
                .replace("\n", "\\n")
                .replace("\r", "\\r");
    }
851104
private static void escapeXml(final char[] text, final int offset, final int len, final Writer writer,
                                 final XmlEscapeSymbols symbols, final XmlEscapeType type, final XmlEscapeLevel level)
                                 throws IOException {

        if (writer == null) {
            throw new IllegalArgumentException("Argument 'writer' cannot be null");
        }

        if (type == null) {
            throw new IllegalArgumentException("The 'type' argument cannot be null");
        }

        if (level == null) {
            throw new IllegalArgumentException("The 'level' argument cannot be null");
        }

        final int textLen = (text == null? 0 : text.length);

        if (offset < 0 || offset > textLen) {
            throw new IllegalArgumentException(
                    "Invalid (offset, len). offset=" + offset + ", len=" + len + ", text.length=" + textLen);
        }

        if (len < 0 || (offset + len) > textLen) {
            throw new IllegalArgumentException(
                    "Invalid (offset, len). offset=" + offset + ", len=" + len + ", text.length=" + textLen);
        }

        XmlEscapeUtil.escape(text, offset, len, writer, symbols, type, level);

    }
266784
@SuppressWarnings("RedundantStringConstructorCall") // avoid String substring memory leak in JDK 1.6
    private String trimNonXmlElements(String path) {
        if(path != null && path.length() > 0) {
            int pos = path.lastIndexOf(">");
            if(pos > -1) {
                path = new String(path.substring(0, pos+1));
            }
        }
        return path;
    }
915228
public static String escapeXML(String s, boolean onlyASCII) {
        char cc[] = s.toCharArray();
        int len = cc.length;
        StringBuffer sb = new StringBuffer();
        for (int k = 0; k < len; ++k) {
            int c = cc[k];
            switch (c) {
                case '<':
                    sb.append("&lt;");
                    break;
                case '>':
                    sb.append("&gt;");
                    break;
                case '&':
                    sb.append("&amp;");
                    break;
                case '"':
                    sb.append("&quot;");
                    break;
                case '\'':
                    sb.append("&apos;");
                    break;
                default:
                	if ((c == 0x9) || (c == 0xA) || (c == 0xD)
                		|| ((c >= 0x20) && (c <= 0xD7FF))
                		|| ((c >= 0xE000) && (c <= 0xFFFD))
                		|| ((c >= 0x10000) && (c <= 0x10FFFF))) { 
                		if (onlyASCII && c > 127)
                			sb.append("&#").append(c).append(';');
                		else 
                			sb.append((char)c);
                	}
            }
        }
        return sb.toString();
    }
202586
public UnprotectedStringBuffer readInnerText() throws XMLException, IOException {
		if (!Type.START_ELEMENT.equals(event.type))
throw new IOException("Invalid call of readInnerText: it must be called on a start element, current event type is: " + event.type);
		if (event.isClosed) return new UnprotectedStringBuffer();
		UnprotectedStringBuffer elementName = event.text;
		UnprotectedStringBuffer innerText = new UnprotectedStringBuffer();
		do {
			try { next(); }
			catch (EOFException e) {
				throw new XMLException(getPosition(), "Unexpected end", "readInnerText(" + elementName.toString() + ")");
			}
			if (Type.COMMENT.equals(event.type)) continue;
			if (Type.TEXT.equals(event.type)) {
				innerText.append(event.text);
				continue;
			}
			if (Type.START_ELEMENT.equals(event.type)) {
				closeElement();
				continue;
			}
			if (Type.END_ELEMENT.equals(event.type)) {
				if (!event.text.equals(elementName))
					throw new XMLException(getPosition(), "Unexpected end element", event.text.asString());
				return innerText;
			}
		} while (true);
	}
468911
public static String omitXmlDeclaration(String xml) {
        if (xml.startsWith("<?xml") && xml.contains("?>")) {
            return xml.substring(xml.indexOf("?>") + 2).trim();
        }

        return xml;
    }