List of usage examples for org.jdom2 Verifier isXMLCharacter
public static boolean isXMLCharacter(final int c)
From source file:org.mycore.common.xml.MCRXMLHelper.java
License:Open Source License
/** * Removes characters that are illegal in XML text nodes or attribute * values./*w w w. ja v a 2 s. c o m*/ * * @param text * the String that should be used in XML elements or attributes * @return the String with all illegal characters removed */ public static String removeIllegalChars(String text) { if (text == null || text.trim().length() == 0) { return text; } if (org.jdom2.Verifier.checkCharacterData(text) == null) { return text; } // It seems we have to filter out invalid XML characters... StringBuilder sb = new StringBuilder(); for (int i = 0; i < text.length(); i++) { if (Verifier.isXMLCharacter(text.charAt(i))) { sb.append(text.charAt(i)); } } return sb.toString(); }