jaxen.jar解析XML文件

在项目中导入jaxen.jar文件

	public void parserXml2(String fileName) {
		File inputXml = new File(fileName);
		SAXReader saxReader = new SAXReader();
		try {
			Document document = saxReader.read(inputXml);
			//查询节点下所有字节点
			List employees = document.selectNodes("/employees/employee");
			  for(Iterator it = employees.iterator(); it.hasNext();){
				  Element node = (Element)it.next();
				  //获得子字点属性及文本
				  System.out.println(node.element("name").getText()+node.element("name").attributeValue("attributevalue"));
				  System.out.println(node.elementText("age"));
				  
			  }
		} catch (DocumentException e) {
			System.out.println(e.getMessage());
		}
	}

你可能感兴趣的:(解析xml)