webservice.utils.WebServiceUtils Maven / Gradle / Ivy
The newest version!
package webservice.utils;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class WebServiceUtils {
private static final Logger LOGGER = Logger.getLogger("WebServiceUtils");
/**
* 根据标签名获得其中的内容;注:标签不带属性
* @param tableName 标签名
* @param xmlString 需要截取的xml
* @return 截取后的字符串
*/
public static String cutOutXml(String tableName, String xmlString) {
String regex = "<" + tableName + ">(.*?)" + tableName + ">";
Pattern pattern = Pattern.compile(regex, Pattern.DOTALL);
Matcher matcher = pattern.matcher(xmlString);
if (matcher.find()) {
return matcher.group(1);
} else {
LOGGER.log(Level.WARNING,tableName+"标签不存在或内容为空。");
return null;
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy