| | |
| | | try { |
| | | SAXReader reader = new SAXReader(); |
| | | Document document = reader.read(new File(xmlFilePath)); |
| | | //获取根元素 |
| | | Element rootElement = document.getRootElement(); |
| | | //获取根元素下的所有子元素 |
| | | /*List<Element> list = rootElement.elements(); |
| | | if(list!=null&&map!=null){ |
| | | for (Element e:list) { |
| | | for (Map.Entry<String, String> entry:map.entrySet()) { |
| | | String mapKey = entry.getKey(); |
| | | String mapValue = entry.getValue(); |
| | | if(e.getName().equals(mapKey)){ |
| | | e.setText(mapValue); |
| | | } |
| | | } |
| | | } |
| | | OutputFormat format = OutputFormat.createPrettyPrint(); |
| | | //format.setEncoding("UTF-8");//默认的编码就是UTF-8 |
| | | XMLWriter writer = new XMLWriter( new FileOutputStream(xmlFilePath), format ); |
| | | writer.write( document ); |
| | | }else{ |
| | | res=false; |
| | | }*/ |
| | | Node node= document.selectSingleNode("//property[@name='cronExpression']/value");//确保节点是真的唯一 |
| | | |
| | | |
| | | for (Map.Entry<String, String> entry:map.entrySet()) { |
| | | String mapKey = entry.getKey(); |
| | | String mapValue = entry.getValue(); |
| | | //得到第一个mapKey节点 |
| | | Node node=document.selectSingleNode("//"+mapKey); |
| | | node.setText(mapValue); |
| | | } |
| | | OutputFormat format = OutputFormat.createPrettyPrint(); |
| | | //format.setEncoding("UTF-8");//默认的编码就是UTF-8 |
| | | format.setEncoding("UTF-8");//默认的编码就是UTF-8 |
| | | XMLWriter writer = new XMLWriter( new FileOutputStream(xmlFilePath), format ); |
| | | writer.write( document ); |
| | | } catch (DocumentException | FileNotFoundException | UnsupportedEncodingException e) { |
| | |
| | | Map map=new HashMap() ; |
| | | //FileInfo fileInfo=XmlFileOpreate.readXml(filePath); |
| | | //System.out.println(fileInfo); |
| | | /* map.put("ChainRes", "50.0"); |
| | | map.put("ChainRes", "50.0"); |
| | | map.put("battTestNum","9"); |
| | | map.put("battModel","SD-001"); |
| | | map.put("batt_res","4.0"); |
| | |
| | | map.put("HighTempAlarm","50"); |
| | | map.put("VERSION","V2.0"); |
| | | map.put("ResGoodCoeK3","1.25"); |
| | | map.put("sample_percent","30");*/ |
| | | map.put("sample_percent","30"); |
| | | map.put("VERSION","V2.0"); |
| | | /* map.put("battBrand","双登lxw"); |
| | | map.put("battBrand","双登lxw"); |
| | | map.put("batt_group_name","后备电源室1#UPS系统lxw"); |
| | | map.put("battStation","鼓楼站lxw");*/ |
| | | map.put("battStation","鼓楼站lxw"); |
| | | |
| | | XmlFileOpreate.writeXml(map,filePath); |
| | | } |