Java XML String Create toXMLString(String org)

Here you can find the source of toXMLString(String org)

Description

to XML String

License

Open Source License

Declaration

public static String toXMLString(String org) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static String toXMLString(String org) {
        if (org == null)
            return "";

        StringBuffer result = new StringBuffer(org.length());
        char[] chars = org.toCharArray();
        for (int i = 0; i < chars.length; i++) {
            if (chars[i] == '<')
                result.append("&lt;");
            else if (chars[i] == '>')
                result.append("&gt;");
            else if (chars[i] == '&')
                result.append("&amp;");
            else if (chars[i] == '\r')
                result.append("&#13;");
            else if (chars[i] == '\n')
                result.append("&#10;");
            else if (chars[i] == '\"')
                result.append("&#34;");
            else//www . j  av  a  2s  . c o  m
                result.append(chars[i]);
        }
        return result.toString();
    }
}

Related

  1. toXML(String valor)
  2. toXMLString(final boolean[] array)
  3. toXmlString(float value)
  4. toXMLString(String in)
  5. toXMLString(String javaString)
  6. toXmlString(String s)
  7. toXMLString(String str)
  8. toXMLString(String string)
  9. toXMLString(String t)