Java Utililty Methods XML Quote

List of utility methods to do XML Quote

Description

The list of methods to do XML Quote are organized into topic(s).

Method

StringquoteXML(String string)
Escapes specified string (that is, '<' is replaced by "&#60;", '&' is replaced by "&#38;", etc) then quotes the escaped string.
StringBuffer quoted = new StringBuffer();
quoted.append('\"');
escapeXML(string, quoted);
quoted.append('\"');
return quoted.toString();
StringquoteXML(String string)
Quotes XML special characters and characters above 127 in the specified string.
StringBuilder buffer = new StringBuilder();
for (char c : string.toCharArray()) {
    if (c == '<')
        buffer.append("&lt;");
    else if (c == '>')
        buffer.append("&gt;");
    else if (c == '&')
        buffer.append("&amp;");
...
StringquoteXML(String xmlFragment)
A convenience method that allows for XML fragments to be stored in larger XML documents without these fragments interfering with the containing document.
if (!xmlFragment.startsWith(XML_QUOTE_PREFIX)) {
    return (XML_QUOTE_PREFIX + xmlFragment + XML_QUOTE_SUFFIX);
return xmlFragment;
StringquoteXmlContent(String x)
Replace special characters with entities for XML attributes.
return replace(x, xmlInC, xmlOutC);
StringquoteXMLValue(final Object o)
Convert the object into XML safe string.
if (o == null) {
    return null;
StringBuilder input = new StringBuilder(o.toString());
StringBuilder output = new StringBuilder(input.length());
int seqStart = 0;
int seqEnd = 0;
for (int count = 0; count < input.length(); count++) {
...
StringquoteXMLValue(Object o)
Convert the object into XML safe string
if (o == null) {
    return null;
String s = o.toString();
StringBuilder str = new StringBuilder(s.length() * 5 / 4);
int seqStart = 0;
int seqEnd = 0;
for (int count = 0; count < s.length(); count++) {
...