欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

webservice 读取xml文件

程序员文章站 2022-06-11 08:24:34
...
		 SAXBuilder saxBuilder = new SAXBuilder();
		 Document doc = null;
		 try {
			doc = saxBuilder.build("D:\\re.xml");
		} catch (JDOMException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		 
		 
		 Format format = Format.getPrettyFormat();    
		//配置xml文档的字符为gb2312,解决中文问题   
		 format.setEncoding("gb2312");
		 XMLOutputter xmlout = new XMLOutputter(format);   
		   
		 ByteArrayOutputStream bo = new ByteArrayOutputStream();   
		   
		 try {
			xmlout.output(doc,bo);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}    
		   
		 String xmlStr = bo.toString();  
		 XmlparseUtil xmlUtil = new XmlparseUtil();		
		 List<Map<String,String>> mapList = new ArrayList<Map<String,String>>();
		 List<HoleHostDataset> datasetList = new ArrayList<HoleHostDataset>();
		// holeHostDatasetService.saveDatasets(datasetList);
		 
		 
		 List<Map<String,String>> secList = new ArrayList<Map<String,String>>();
		 
		 try {
			secList = xmlUtil.xmlElementsm(xmlStr);
		} catch (JDOMException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		 
		 
		 try {
			 mapList =  xmlUtil.xmlElementsm(xmlStr);
		} catch (JDOMException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
			for(int i=0;i<mapList.size();i++){
				HoleHostDataset dataset = new HoleHostDataset();
				dataset.setVulnId(mapList.get(i).get("vuln-id"));
				dataset.setVulnName(mapList.get(i).get("vuln-name"));
				//dataset.setCreateTime(createTime);
				dataset.setVulnSeverity(1);
				dataset.setAssetIp(mapList.get(i).get("asset-IP"));
				dataset.setAssetPort(Integer.parseInt(mapList.get(i).get("asset-port")));
				dataset.setPortType(mapList.get(i).get("port-type"));
				dataset.setAssetProtocol(mapList.get(i).get("asset-protocol"));
				dataset.setAssetService(mapList.get(i).get("asset-service"));
				dataset.setSystemAffected(mapList.get(i).get("system-affected"));
//				if(mapList.get(i).get("remedy")!=null){
//					dataset.setRemedy(mapList.get(i).get("remedy").substring(1));
//				}else{
					dataset.setRemedy(mapList.get(i).get("remedy"));
//				}
				
				dataset.setDescription(mapList.get(i).get("description"));
				dataset.setVulnValue(1);
				dataset.setVulnStatus(1);
				dataset.setCveName(mapList.get(i).get("cve-name"));
				if(mapList.get(i).get("cve-status") == null){
					dataset.setCveStatus(0);
				}else{
					dataset.setCveStatus(Integer.parseInt(mapList.get(i).get("cve-status")));
				}
				dataset.setCveDesc(mapList.get(i).get("cve-desc"));
				dataset.setHoldTaskId(44);
				//dataset.setCompTime(compTime);
				
				datasetList.add(dataset);
				
			}
		
			holeHostDatasetService.saveDatasets(datasetList);





相关标签: webService