Formats the given text as a XML CDATA element - Android java.lang

Android examples for java.lang:String XML

Description

Formats the given text as a XML CDATA element

Demo Code

import android.content.Context;
import android.text.Html;
import android.text.Spanned;
import android.text.TextUtils;
import android.text.format.DateUtils;
import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main{

    /**//from w w w  . j a va2 s .  co m
     * Formats the given text as a XML CDATA element. This includes adding the starting and ending
     * CDATA tags. Please notice that this may result in multiple consecutive CDATA tags.
     *
     * @param text the given text
     */
    public static String formatCData(String text) {
        return "<![CDATA[" + text.replaceAll("]]>", "]]]]><![CDATA[>")
                + "]]>";
    }

}

Related Tutorials