Here you can find the source of xmlEncode(String s)
Parameter | Description |
---|---|
s | string to encode |
public static String xmlEncode(String s)
//package com.java2s; /*/*from w ww. j ava2 s . c o m*/ * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License * as published by the Free Software Foundation. For the full * license text, see http://www.gnu.org/licenses/lgpl.html. */ public class Main { /** * Encode string to XML. * This will encode the following raw characters: * <ul> * <li>" = &quot;</li> * <li>> = &gt;</li> * <li>< = &lt;</li> * <li>& = &amp;</li> * </ul> * * @param s string to encode * @return encoded string */ public static String xmlEncode(String s) { return s.replaceAll("&", "&").replaceAll("\"", """).replaceAll(">", ">").replaceAll("<", "<") .replaceAll("'", "'"); } }