| | |
| | | import java.util.*; |
| | | |
| | | public class XmlFileOpreate { |
| | | //解析FBR-6000NT基础2.7 |
| | | public static FileInfo readFBR_6000NT_jc(String xmlFilePath){ |
| | | FileInfo fileInfo=new FileInfo();//文件信息 |
| | | FileParam fparam=fileInfo.getFileParam();//文件参数 |
| | | boolean res = true; |
| | | try |
| | | { |
| | | SAXReader reader = new SAXReader(); |
| | | FileInputStream fiso=new FileInputStream(xmlFilePath); |
| | | Document document = reader.read(fiso); |
| | | Element rootnode = document.getRootElement(); |
| | | |
| | | //解析xml文件 |
| | | public static FileInfo readXml(String xmlFilePath) |
| | | { |
| | | Element node;//根节点 |
| | | Element file_node;//文件节点 |
| | | |
| | | //------------------------------------------------------------// |
| | | node = rootnode.element("TEST_TIME"); |
| | | String testTime=node.getTextTrim(); |
| | | testTime=testTime.replace("_"," "); |
| | | fparam.setTestTime(ActionUtil.sdfwithALL.parse(testTime)); |
| | | //------------------------------------------------------------// |
| | | node = rootnode.element("VERSION"); |
| | | fparam.setVersion(node.getTextTrim()); |
| | | //------------------------------------------------------------// |
| | | node = rootnode.element("BATT_PARAM"); |
| | | file_node=node.element("batt_group_name"); |
| | | fparam.setBattGroupName(file_node.getTextTrim()); |
| | | |
| | | file_node=node.element("batt_producer"); |
| | | if(file_node!=null){ |
| | | fparam.setBattProducer(file_node.getTextTrim()); |
| | | } |
| | | file_node=node.element("batt_cap"); |
| | | fparam.setBattCap(Float.parseFloat(file_node.getTextTrim())); |
| | | file_node=node.element("batt_count"); |
| | | fparam.setBattCount(Integer.parseInt(file_node.getTextTrim())); |
| | | |
| | | file_node=node.element("batt_vol"); |
| | | fparam.setBattVol(Float.parseFloat(file_node.getTextTrim())); |
| | | file_node=node.element("batt_vol_good"); |
| | | if(file_node!=null){ |
| | | fparam.setBattVolGood(Float.parseFloat(file_node.getTextTrim())); |
| | | } |
| | | file_node=node.element("batt_vol_bad"); |
| | | if(file_node!=null){ |
| | | fparam.setBattVolBad(Float.parseFloat(file_node.getTextTrim())); |
| | | } |
| | | |
| | | file_node=node.element("batt_res"); |
| | | fparam.setBattRes(Float.parseFloat(file_node.getTextTrim())); |
| | | file_node=node.element("batt_res_good"); |
| | | if(file_node!=null){ |
| | | fparam.setBattResGood(Float.parseFloat(file_node.getTextTrim())); |
| | | } |
| | | file_node=node.element("batt_res_bad"); |
| | | if(file_node!=null){ |
| | | fparam.setBattResBad(Float.parseFloat(file_node.getTextTrim())); |
| | | } |
| | | |
| | | file_node=node.element("batt_ser"); |
| | | fparam.setBattSer(Float.parseFloat(file_node.getTextTrim())); |
| | | file_node=node.element("batt_ser_good"); |
| | | if(file_node!=null){ |
| | | fparam.setBattSerGood(Float.parseFloat(file_node.getTextTrim())); |
| | | } |
| | | file_node=node.element("batt_ser_bad"); |
| | | if(file_node!=null){ |
| | | fparam.setBattSerBad(Float.parseFloat(file_node.getTextTrim())); |
| | | } |
| | | |
| | | file_node=node.element("concount_pb"); |
| | | fparam.setConcountPb(Integer.parseInt(file_node.getTextTrim())); |
| | | |
| | | file_node=node.element("conn_res"); |
| | | if(file_node!=null){ |
| | | fparam.setConnRes(Float.parseFloat(file_node.getTextTrim())); |
| | | } |
| | | file_node=node.element("conn_res_good"); |
| | | if(file_node!=null){ |
| | | fparam.setConnResGood(Float.parseFloat(file_node.getTextTrim())); |
| | | } |
| | | file_node=node.element("conn_res_bad"); |
| | | if(file_node!=null){ |
| | | fparam.setConnResBad(Float.parseFloat(file_node.getTextTrim())); |
| | | } |
| | | //-----根据groupNum的值读取测试数据---------------------------// |
| | | Iterator nodes = rootnode.elementIterator("node_batt_num"); |
| | | while (nodes.hasNext()){ |
| | | node= (Element) nodes.next(); |
| | | BattgroupInfo battInfo=new BattgroupInfo(); |
| | | List<BattgroupData> battDataList=new ArrayList(); |
| | | BattgroupData battData=new BattgroupData(); |
| | | battData.setMonNum(Integer.parseInt(node.attributeValue("batt_num"))); |
| | | file_node=node.element("bv_1"); |
| | | battData.setBv(file_node.getTextTrim()); |
| | | file_node=node.element("br_1"); |
| | | battData.setBr(file_node.getTextTrim()); |
| | | file_node=node.element("bs_1"); |
| | | battData.setBs(file_node.getTextTrim()); |
| | | file_node=node.element("cr_1"); |
| | | battData.setCr(file_node.getTextTrim()); |
| | | battDataList.add(battData); |
| | | battInfo.setBattDataList(battDataList); |
| | | fileInfo.getBattInfoList().add(battInfo); |
| | | } |
| | | fileInfo.setFileParam(fparam); |
| | | fiso.close(); |
| | | } catch (NullPointerException | NumberFormatException | DocumentException | ParseException | FileNotFoundException e) { |
| | | res = false; |
| | | e.printStackTrace(); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } finally { |
| | | if(false == res) |
| | | return null; |
| | | } |
| | | return fileInfo; |
| | | } |
| | | //解析FBR-6000NT带标记版本2.0 |
| | | public static FileInfo readFBR_6000NT_bj(String xmlFilePath){ |
| | | boolean res = true; |
| | | FileInfo fileInfo=new FileInfo();//文件信息 |
| | | FileParam fparam=fileInfo.getFileParam();//文件参数 |
| | |
| | | //------------------------------------------------------------// |
| | | node = rootnode.element("TEST_TIME"); |
| | | String testTime=node.getTextTrim(); |
| | | testTime.replace("_"," "); |
| | | fparam.setTestTime(ActionUtil.sdfwithALL.parse(testTime)); |
| | | //------------------------------------------------------------// |
| | | node = rootnode.element("VERSION"); |
| | |
| | | } |
| | | return fileInfo; |
| | | } |
| | | //解析xml文件 |
| | | public static FileInfo readXml(String xmlFilePath) |
| | | { |
| | | FileInfo fileInfo=new FileInfo(); |
| | | try |
| | | { |
| | | SAXReader reader = new SAXReader(); |
| | | FileInputStream fiso=new FileInputStream(xmlFilePath); |
| | | Document document = reader.read(fiso); |
| | | Element rootnode = document.getRootElement(); |
| | | |
| | | //------------------------------------------------------------// |
| | | Element node = rootnode.element("VERSION"); |
| | | if(node!=null){ |
| | | String version=node.getTextTrim(); |
| | | switch (version){ |
| | | case "V2.0": fileInfo=readFBR_6000NT_bj(xmlFilePath);break; |
| | | case "V2.7": fileInfo=readFBR_6000NT_jc(xmlFilePath);break; |
| | | default:break; |
| | | } |
| | | } |
| | | fiso.close(); |
| | | } catch (NullPointerException | NumberFormatException | DocumentException | FileNotFoundException e) { |
| | | e.printStackTrace(); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return fileInfo; |
| | | } |
| | | |
| | | public static boolean writeXml( Map<String,String> map,String xmlFilePath){ |
| | | boolean res=true; |
| | |
| | | } |
| | | |
| | | public static void main(String[] args) { |
| | | String filePath="D://2022-06-14 16-02-34.xml"; |
| | | String filePath="D:\\fileTest\\FBR-5000CT -原数据20221031\\\\2022-10-31_09-14-48.xml"; |
| | | Map map=new HashMap() ; |
| | | //FileInfo fileInfo=XmlFileOpreate.readXml(filePath); |
| | | //System.out.println(fileInfo); |
| | | FileInfo fileInfo=XmlFileOpreate.readXml(filePath); |
| | | System.out.println(fileInfo); |
| | | map.put("ChainRes", "50.0"); |
| | | map.put("battTestNum","9"); |
| | | map.put("battModel","SD-001"); |
| | |
| | | map.put("batt_group_name","后备电源室1#UPS系统lxw"); |
| | | map.put("battStation","鼓楼站lxw"); |
| | | |
| | | XmlFileOpreate.writeXml(map,filePath); |
| | | //XmlFileOpreate.writeXml(map,filePath); |
| | | } |
| | | } |