Java XML Encode unwrapCdata(String sText)

Here you can find the source of unwrapCdata(String sText)

Description

If the text is wrapped with a "[CDATA[ ]]" tag then it is removed and the text inside is returned.

License

Open Source License

Parameter

Parameter Description
sText The text containing a CDATA wrapper.

Return

The text without the CDATA wrapper. If it does not contain a CDATA wrapper, it simply returns the same text it was passed.

Declaration

public static String unwrapCdata(String sText) 

Method Source Code

//package com.java2s;

public class Main {
    /**/*from w  ww.  ja  v a  2 s  . c  o  m*/
     * If the text is wrapped with a "[CDATA[ ]]" tag then it is removed and the text inside is returned.
     *
     * @param sText The text containing a CDATA wrapper.
     * @return The text without the CDATA wrapper. If it does not contain a CDATA wrapper, it simply returns the same
     * text it was passed.
     */
    public static String unwrapCdata(String sText) {
        if ((sText != null) && (sText.trim().startsWith("[CDATA[")) && (sText.trim().endsWith("]]"))) {
            return sText.trim().substring(7, sText.trim().length() - 2);
        } else {
            return sText;
        }
    }
}

Related

  1. textToXml(String text)
  2. toXMLCData(String cdata)
  3. toXMLCharData(String javaString)
  4. toXMLEscapedTextExpandingWhitespace(String text)
  5. unwrapCdata(String s)
  6. unwrapCDATA(String str)
  7. xmlEncode(final String text)
  8. XMLEncode(final String value)
  9. xmlEncode(String in)