SAXReader读xml文件

前端之家收集整理的这篇文章主要介绍了SAXReader读xml文件前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
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,119,252</option55>
	</os_dchp_fingerprint>
	<os_dchp_fingerprint osname="Android">
		<option55 version="6.1.3.0">1,59</option55>
	</os_dchp_fingerprint>
</os_dhcp_fingerprints>
原文链接:https://www.f2er.com/xml/299478.html

猜你在找的XML相关文章