Java tutorial
//package com.java2s; /* * $Id$ * * This code is derived from public domain sources. Commercial use is allowed. * However, all rights remain permanently assigned to the public domain. * * XMLUtils.java : A class of static XML utility methods. * * Copyright (C) 2009, 2010 Scott Herman * * This 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, either version 3 of the License, or * (at your option) any later version. * * This code is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this code. If not, see <http://www.gnu.org/licenses/>. * */ public class Main { private static String startXMLFor(String elementName, String argStr) { int tokenIndex = argStr.toLowerCase().indexOf(elementName.toLowerCase()); if (tokenIndex < 1) return null; int startIndex = tokenIndex; while (startIndex >= 0 && argStr.charAt(startIndex) != '<' && (Character.isWhitespace(argStr.charAt(startIndex)) || startIndex == tokenIndex)) { --startIndex; } // while if (startIndex < 0 || argStr.charAt(startIndex) != '<') return null; if (startIndex == 0) return argStr; return argStr.substring(startIndex); } }