解析xml简单实例,后续继续补充.......
2015-10-30 11:40
447 查看
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(); } }
相关文章推荐
- Tomcat8启动时的Error deploying web application directory错误
- string 类型的使用方法
- 版本控制
- LeetCode刷题
- Treap
- Xshell界面输出中文乱码现象解决方法
- SVProgressHUD
- 在Emacs中启用Fcitx输入法
- iis7 500错误日志报 LOG_FILE_MAX_SIZE_TRUNCATE
- Spring MVC篇一、搭建Spring MVC框架
- 数据库什么时候建立索引?
- 数据导出
- 记录一些数据库事物的头条问题
- JAVA中的访问权限
- 高斯模糊相关链接
- 斯坦福大学深度学习与自然语言处理课程解读
- Cocoapod安装 - 管理第三方库
- iOS开发项目自动生成技术文档
- Linux中,特殊宏 __bitwise、 __force、 __init 、__initdata 的使用
- OpenGL三角形几何变换