Selaa lähdekoodia

1.恩泽xml工具添加异常处理

hujing 4 vuotta sitten
vanhempi
commit
9dca8958fe

+ 10 - 8
trans/src/main/java/com/lantone/qc/trans/beilun/util/ez/util/EzXmlUtil.java

@@ -2,6 +2,7 @@ package com.lantone.qc.trans.beilun.util.ez.util;
 
 import com.google.common.collect.Maps;
 import com.lantone.qc.pub.util.StringUtil;
+import lombok.extern.slf4j.Slf4j;
 import org.dom4j.Attribute;
 import org.dom4j.Document;
 import org.dom4j.DocumentHelper;
@@ -16,13 +17,19 @@ import java.util.Map;
  * @author: HUJING
  * @time: 2021/1/4 14:30
  */
+@Slf4j
 public class EzXmlUtil {
 
     public static Map<String, String> analysis(String xml) throws Exception {
         Map<String, String> map = Maps.newLinkedHashMap();
-        Document doc = DocumentHelper.parseText(bom(xml));
-        Element rootElement = doc.getRootElement();
-        findAllNodes(rootElement, map);
+        try {
+            Document doc = DocumentHelper.parseText(bom(xml));
+            Element rootElement = doc.getRootElement();
+            findAllNodes(rootElement, map);
+        } catch (Exception e) {
+            log.error(e.getMessage(), e);
+            throw new Exception("xml解析错误:" + e.getMessage());
+        }
         return map;
     }
 
@@ -55,11 +62,6 @@ public class EzXmlUtil {
         for (Attribute attr : listAttr) {// 遍历所有属性
             //String name = attr.getName();// 属性名称
             if (("fieldelem".equals(labelName)) && StringUtil.isNotBlank(attr.getValue())) {
-                /*
-                if (text.contains(":") && text.indexOf(":") < text.length()) {
-                    text = text.substring(text.indexOf(":") + 1);
-                }
-                 */
                 String fieldelemKey = attr.getValue();// 属性的值
                 String text = node.getStringValue();
                 map.put(fieldelemKey, text);