SAXReader reader = new SAXReader(); Document document=null; try { document = reader.read(new File(System.getProperty("user.dir") + CONfigPATH)); } catch (DocumentException e) { e.printstacktrace(); } //得到xml文件里面的第一个节点 Element root = document.getRootElement(); //得到第一个节点下的所有子节点1 List<Element> tasksChildren = root.elements(); //遍历出所有子节点1 for (Iterator<?> it = taskChildren.iterator(); it.hasNext();) { Element tasksChild = (Element) it.next(); tasks.add(tasksChild); TaskVo taskVo = new TaskVo(); // 得到task的全部属性 taskVo.setId(tasksChild.attributeValue("id")); taskVo.setName(tasksChild.attributeValue("name")); taskVo.setDescription(tasksChild .attributeValue("description")); taskVo.setEnable(Boolean.parseBoolean(tasksChild .attributeValue("enable"))); taskChild.elementText("hostId") } for (Element tast : tasksChildren) { try { //获取节点里面的属性值 tast.attributeValue("id")得到<xxx id="yyyyy" />里面的id值 Document documentTast = reader.read((System.getProperty("user.dir") + AppCf.config_path+"/crawler/"+tast.attributeValue("id")+".xml")); Element roottast = documentTast.getRootElement(); String taskId = tast.attributeValue("id"); dealLabel.dealTask(roottast,taskId); } catch (DocumentException e) { e.printstacktrace(); } }