dom4j读取配置文件
来源:互联网 发布:青岛 大数据 编辑:程序博客网 时间:2024/06/01 08:51
需求:现在需要自定义xml里面的内容(在设计层级关系的时候用到),并用java程序读取xml里面的内容。
xml的文件内容:
<?xml version="1.0" encoding="UTF-8"?><data><function><code>jpo</code><name>对日开发</name><parentCode>wicresoft</parentCode><parentName>微创软件</parentName></function><function><code>bpo</code><name>对欧美开发</name><parentCode>wicresoft</parentCode><parentName>微创软件</parentName></function></data>
解决方法:首先 在项目中加入dom4j.jar 下载地址:http://download.csdn.net/detail/zl544434558/6490555
读取xml文件的代码:
File file = new File("G:\\eclipse_workspace\\javascriptTest\\src\\function.xml");/* * 这里的function.xml放在src目录下 * 这里的文件路径这样做依赖于磁盘,如果你用struts2可以用如下方式获得xml文件路径 * ServletContext servletContext = ServletActionContext.getServletContext() * String realPath = servletContext.getRealPath(/function.xml); */SAXReader reader = new SAXReader();Document document = reader.read(file);Element rootElement = document.getRootElement();Iterator<Element> iterator = rootElement.elementIterator("function");while (iterator.hasNext()) {Element element = iterator.next();element.elementText("code");element.elementText("name");element.elementText("parentCode");element.elementText("parentName");}
- dom4j读取spring配置文件
- dom4j读取配置文件
- dom4j读取配置文件
- dom4j读取配置文件
- XML配置文件的读取--DOM4J
- 使用dom4j读取spring配置文件
- 利用dom4j读取XML配置文件
- 使用dom4j读取xml配置文件
- dom4j实现模拟Spring读取配置文件 注入
- dom4j 读取xml 数据库配置文件 dataconfig
- DOM4J 读取XML配置文件进行数据库连接
- drp—Dom4j读取xml配置文件
- 用dom4j读取配置文件来模拟spring的bean工厂
- Java读取XML配置文件详细总结(dom4j方式)
- Java中通过dom4j读取配置文件实现抽象工厂+反射
- Java中通过dom4j读取配置文件实现抽象工厂+反射
- Java中通过dom4j读取配置文件实现抽象工厂+反射
- 使用dom4j模拟spring工厂来读取配置文件
- 李开复:现代企业需要7种人才
- 怎样用U盘制作启动盘
- 宏观内存信息统计
- 关于Servlet的生命周期
- Ubuntu使用笔记_无线网卡
- dom4j读取配置文件
- word2013每次打开都出现配置进度解决方案
- Android 抽屉导航
- java绘图技术(一)
- 71道经典Android面试题和答案--重要知识点都涉及到了
- 快速排序
- java绘图技术(二)
- Spring 事务传播Propagation类型
- hdu 1071 The area(数学题)