Java tutorial
//package com.java2s; /* Please see the license information at the end of this file. */ public class Main { /** Check that string contains valid XML characters. * * @param xml The XML text to check. * * @return true if the string contains only characters * valid in XML, false otherwise. */ public static boolean iSValidXMLText(String xml) { boolean result = true; if (xml != null) { result = xml.matches( //# ASCII "^([\\x09\\x0A\\x0D\\x20-\\x7E]|" + //# non-overlong 2-byte "[\\xC2-\\xDF][\\x80-\\xBF]|" + //# excluding overlongs "\\xE0[\\xA0-\\xBF][\\x80-\\xBF]|" + //# straight 3-byte "[\\xE1-\\xEC\\xEE\\xEF][\\x80-\\xBF]{2}|" + //# excluding surrogates "\\xED[\\x80-\\x9F][\\x80-\\xBF]|" + //# planes 1-3 "\\xF0[\\x90-\\xBF][\\x80-\\xBF]{2}|" + //# planes 4-15 "[\\xF1-\\xF3][\\x80-\\xBF]{3}|" + //# plane 16 "\\xF4[\\x80-\\x8F][\\x80-\\xBF]{2})*$"); } return result; } }