SAXReader读xml文件

前端之家收集整理的这篇文章主要介绍了SAXReader读xml文件前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
  1. public static void main(String[] args) {
  2. final String OS_VERSION_FILE_PATH = AhDirTools.getOsDetectionDir()+"os_dhcp_fingerprints_changes.xml";
  3. Map<String,String> hm = new HashMap<>();
  4.  
  5. SAXReader reader = new SAXReader();
  6. Document document;
  7. try {
  8. document = reader.read(new File(OS_VERSION_FILE_PATH));
  9. Element root = document.getRootElement();
  10. List<?> fingerprintElems = root.elements();
  11. for (Object obj : fingerprintElems) {
  12. Element fingerprintElem = (Element) obj;
  13. String node_fingerprint_name = fingerprintElem.getName();
  14. String osName = fingerprintElem.attributeValue("osname");
  15. for(Iterator iterator = fingerprintElem.elementIterator();iterator.hasNext();){
  16. Element option55Elem = (Element) iterator.next();
  17. String node_option55_name = option55Elem.getName();
  18. String node_option55_text = option55Elem.getText();
  19. Attribute version = option55Elem.attribute("version");
  20. String version_name = version.getName();
  21. String version_text = version.getText();
  22. if(NmsUtil.compareSoftwareVersion("6.1.3.0",version_text) >=0){
  23. if(!hm.containsKey(node_option55_text)){
  24. hm.put(node_option55_text,osName);
  25. }
  26. }
  27. }
  28. }
  29. } catch (DocumentException e) {
  30. // TODO Auto-generated catch block
  31. e.printStackTrace();
  32. }
  33. }


  1. <?xml version="1.0" encoding="UTF-8"?>
  2.  
  3. <os_dhcp_fingerprints>
  4. <os_dchp_fingerprint osname="CrOS">
  5. <option55 version="6.1.2.0">1,121,33,3,6,12,15,26,28,51,54,58,59,119</option55>
  6. <option55 version="6.1.2.0">1,119,252</option55>
  7. </os_dchp_fingerprint>
  8. <os_dchp_fingerprint osname="Android">
  9. <option55 version="6.1.3.0">1,59</option55>
  10. </os_dchp_fingerprint>
  11. </os_dhcp_fingerprints>

猜你在找的XML相关文章