关闭

SAXReader读xml文件

542人阅读 评论(0) 收藏 举报
分类:
public static void main(String[] args) {
	final String OS_VERSION_FILE_PATH = AhDirTools.getOsDetectionDir()+"os_dhcp_fingerprints_changes.xml";
	Map<String,String> hm = new HashMap<>();

	SAXReader reader = new SAXReader();
	Document document;
	try {
		document = reader.read(new File(OS_VERSION_FILE_PATH));
		Element root = document.getRootElement();
		List<?> fingerprintElems = root.elements();
		for (Object obj : fingerprintElems) {
			Element fingerprintElem = (Element) obj;
			String node_fingerprint_name = fingerprintElem.getName();
			String osName = fingerprintElem.attributeValue("osname");
			for(Iterator iterator = fingerprintElem.elementIterator();iterator.hasNext();){
				Element option55Elem = (Element) iterator.next();
				String node_option55_name = option55Elem.getName();
				String node_option55_text = option55Elem.getText();
				Attribute version = option55Elem.attribute("version");
				String version_name = version.getName();
				String version_text = version.getText();
				
				if(NmsUtil.compareSoftwareVersion("6.1.3.0",version_text) >=0){
					if(!hm.containsKey(node_option55_text)){
						hm.put(node_option55_text, osName);
					}
				}
			}
		}
	} catch (DocumentException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
}


<?xml version="1.0" encoding="UTF-8"?>

<os_dhcp_fingerprints>
	<os_dchp_fingerprint osname="CrOS">
		<option55 version="6.1.2.0">1,121,33,3,6,12,15,26,28,51,54,58,59,119</option55>
		<option55 version="6.1.2.0">1,121,33,3,6,12,15,26,28,51,54,58,59,119,252</option55>
	</os_dchp_fingerprint>
	<os_dchp_fingerprint osname="Android">
		<option55 version="6.1.3.0">1,33,3,6,15,26,28,51,58,59</option55>
	</os_dchp_fingerprint>
</os_dhcp_fingerprints>


0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:216571次
    • 积分:1574
    • 等级:
    • 排名:千里之外
    • 原创:24篇
    • 转载:32篇
    • 译文:0篇
    • 评论:11条
    文章分类
    最新评论