Wrap input with XML CDATA tag - Java XML

Java examples for XML:CDATA

Description

Wrap input with XML CDATA tag

Demo Code


//package com.java2s;

public class Main {
    public static void main(String[] argv) throws Exception {
        String input = "java2s.com";
        System.out.println(wrapCDATA(input));
    }/*  w  ww  . j a  v  a2  s. c o  m*/

    private static final String CDATA_WRAP_BEGIN = "<![CDATA[";
    private static final String CDATA_WRAP_END = "]]>";

    /**
     * Wrap input with CDATA tag
     *
     * @param input Input string
     * @return Input string wrapped with CDATA
     */
    public static String wrapCDATA(String input) {
        return CDATA_WRAP_BEGIN + input + CDATA_WRAP_END;
    }
}

Related Tutorials