648540858
2024-03-07 d8b24fc7950cf0ae31e6db41bfd1d698e0fdeecc
XmlUtil添加直接获取Double和Integer的方法
1个文件已修改
44 ■■■■■ 已修改文件
src/main/java/com/genersoft/iot/vmp/gb28181/utils/XmlUtil.java 44 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/genersoft/iot/vmp/gb28181/utils/XmlUtil.java
@@ -78,6 +78,50 @@
    }
    /**
     * 获取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节点,适用于 多节点数据
     *
     * @param node     node