XmlUtil添加直接获取Double和Integer的方法

结构优化
648540858 2024-03-07 14:49:46 +08:00
parent 5bf87ca330
commit d8b24fc795
1 changed files with 44 additions and 0 deletions

View File

@ -77,6 +77,50 @@ public class XmlUtil {
return null == e ? null : e.getText().trim(); return null == e ? null : e.getText().trim();
} }
/**
* elementtext
*
* @param em
* @param tag tag
* @return
*/
public static Double getDouble(Element em, String tag) {
if (null == em) {
return null;
}
Element e = em.element(tag);
if (null == e) {
return null;
}
String text = e.getText().trim();
if (ObjectUtils.isEmpty(text) || !NumberUtils.isParsable(text)) {
return null;
}
return Double.parseDouble(text);
}
/**
* elementtext
*
* @param em
* @param tag tag
* @return
*/
public static Integer getInteger(Element em, String tag) {
if (null == em) {
return null;
}
Element e = em.element(tag);
if (null == e) {
return null;
}
String text = e.getText().trim();
if (ObjectUtils.isEmpty(text) || !NumberUtils.isParsable(text)) {
return null;
}
return Integer.parseInt(text);
}
/** /**
* xml * xml
* *