Browse Source

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

648540858 1 năm trước cách đây
mục cha
commit
d8b24fc795

+ 44 - 0
src/main/java/com/genersoft/iot/vmp/gb28181/utils/XmlUtil.java

@@ -77,6 +77,50 @@ public class XmlUtil {
         return null == e ? null : e.getText().trim();
     }
 
+    /**
+     * 获取element对象的text的值
+     *
+     * @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);
+    }
+
+    /**
+     * 获取element对象的text的值
+     *
+     * @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节点,适用于 多节点数据
      *