解析xml简单实例,后续继续补充.......

   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();
}
  }

相关文章

php输出xml格式字符串
J2ME Mobile 3D入门教程系列文章之一
XML轻松学习手册
XML入门的常见问题(一)
XML入门的常见问题(三)
XML轻松学习手册(2)XML概念