Java tutorial
//package com.java2s; /* // $Id: //open/mondrian/src/main/mondrian/xom/XMLUtil.java#1 $ // This software is subject to the terms of the Common Public License // Agreement, available at the following URL: // http://www.opensource.org/licenses/cpl.html. // (C) Copyright 2001-2002 Kana Software, Inc. and others. // All Rights Reserved. // You must accept the terms of that agreement to use this software. // // jhyde, 3 October, 2001 */ public class Main { /** * Determine if a String contains any XML special characters, return true * if it does. If this function returns true, the string will need to be * encoded either using the stringEncodeXML function above or using a * CDATA section. Note that MSXML has a nasty bug whereby whitespace * characters outside of a CDATA section are lost when parsing. To * avoid hitting this bug, this method treats many whitespace characters * as "special". * @param input the String to scan for XML special characters. * @return true if the String contains any such characters. */ public static boolean stringHasXMLSpecials(String input) { for (int i = 0; i < input.length(); i++) { char c = input.charAt(i); switch (c) { case '<': case '>': case '"': case '\'': case '&': case '\t': case '\n': case '\r': return true; } } return false; } }