Java XML String Create toXMLString(String in)

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

Description

Do character conversions to convert a string to an XML parsable string

License

Apache License

Parameter

Parameter Description
in non-null input string

Return

non-null return string

Declaration

public static String toXMLString(String in) 

Method Source Code

//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("&quot;");
                break;
            case '&':
                sb.append("&amp;");
                break;
            case '\'':
                sb.append("&apos;");
            case '<':
                sb.append("&lt;");
                break;
            case '>':
                sb.append("&gt;");
                break;
            default:
                sb.append((char) c);
            }
        }

        return (sb.toString());
    }
}

Related

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