transform String To Xml - Java XML

Java examples for XML:XML Transform

Description

transform String To Xml

Demo Code

// This source code is available under agreement available at
//package com.java2s;

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

    public static String transformStringToXml(String value) {
        return value
                .replaceAll("&lt;", "<").replaceAll("&gt;", ">").replaceAll("&amp;", "&").replaceAll("&quot;", "\"") //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
                .replaceAll("&apos;", "'"); //$NON-NLS-1$ //$NON-NLS-2$
    }
}

Related Tutorials