Java XML Unescape unescapeXml(String xml)

Here you can find the source of unescapeXml(String xml)

Description

unescape Xml

License

Open Source License

Declaration

public static String unescapeXml(String xml) throws Exception 

Method Source Code

//package com.java2s;

public class Main {
    public static String unescapeXml(String xml) throws Exception {
        if (xml == null)
            return null;

        StringBuilder b = new StringBuilder();
        int i = 0;
        while (i < xml.length()) {
            if (xml.charAt(i) == '&') {
                StringBuilder e = new StringBuilder();
                i++;/*ww w  . ja va 2 s .com*/
                while (xml.charAt(i) != ';') {
                    e.append(xml.charAt(i));
                    i++;
                }
                if (e.toString().equals("lt"))
                    b.append("<");
                else if (e.toString().equals("gt"))
                    b.append(">");
                else if (e.toString().equals("amp"))
                    b.append("&");
                else if (e.toString().equals("quot"))
                    b.append("\"");
                else if (e.toString().equals("mu"))
                    b.append((char) 956);
                else
                    throw new Exception("unknown XML entity \""
                            + e.toString() + "\"");
            } else
                b.append(xml.charAt(i));
            i++;
        }
        return b.toString();
    }
}

Related

  1. unescapeXml(String str)
  2. unescapeXML(String text)
  3. unescapeXML(String text)
  4. unescapeXml(String value)
  5. unescapeXml(String value)
  6. unescapeXML(String xml)
  7. unescapeXmlChars(String source)
  8. unescapeXMLComment(String content)
  9. unescapeXMLEntities(String text)