Java Utililty Methods XML String Create

List of utility methods to do XML String Create

Description

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

Method

StringtoXMLString(String string)
to XML String
if (string == null || string.isEmpty())
    return ""; 
StringBuffer xmlString = new StringBuffer();
int stringLength = string.length();
for (int i = 0; i < stringLength; i++) {
    char c = string.charAt(i);
    if (c == '"')
        xmlString.append("&quot;"); 
...
StringtoXMLString(String t)
to XML String
String s = t.toString();
StringBuffer sb = new StringBuffer();
for (int idx = 0; idx < s.length(); idx++) {
    char ch = s.charAt(idx);
    if (ch == '<') {
        sb.append("&lt;");
    } else if (ch == '&') {
        sb.append("&amp;");
...
StringtoXMLString(String text)
Converts a text into a XML string by converting special characters into where corresponding entities.
StringBuffer buffer = new StringBuffer();
int len = text.length();
for (int i = 0; i < len; i++) {
    char ch = text.charAt(i);
    if ((ch < 0x0020) || (ch > 0x007e)) {
        buffer.append("&#");
        buffer.append((int) ch);
        buffer.append(";");
...
StringtoXMLUnescapedText(final String text)
to XML Unescaped Text
return text.replaceAll("&lt;", "<").replaceAll("&gt;", ">").replaceAll("&quot;", "\"").replaceAll("&amp;",
        "&");