transform Xml To String - Java XML

Java examples for XML:XML Transform

Description

transform Xml To String

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 XmlString = "java2s.com";
        System.out.println(transformXmlToString(XmlString));
    }/*from w  w  w  . ja v a2 s .  co m*/

    public static String transformXmlToString(String XmlString) {
        return XmlString
                .replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").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