Here you can find the source of xmlEncode(String text)
Parameter | Description |
---|---|
text | the text |
public static String xmlEncode(String text)
//package com.java2s; //License from project: Apache License public class Main { /**//from w w w. j a va 2 s . co m * Encodes the text into safe XML by replacing < > and & with XML tokens * * @param text the text * @return the encoded text */ public static String xmlEncode(String text) { if (text == null) { return ""; } // must replace amp first, so we don't replace < to amp later text = text.replaceAll("&", "&"); text = text.replaceAll("\"", """); text = text.replaceAll("<", "<"); text = text.replaceAll(">", ">"); return text; } }