import java.io.File;

import java.util.List;



import org.dom4j.Document;

import org.dom4j.DocumentException;

import org.dom4j.Element;

import org.dom4j.io.SAXReader;



public class Test {



/**

* @param args

*/

public static void main(String[] args) {

// TODO Auto-generated method stub



SAXReader saxReader = new SAXReader();

try {

Document document = saxReader.read(new File("d://demo.xml"));

Element root = document.getRootElement();

List actions = root.elements("action");

for (int i = 0; i < actions.size(); i++) {

Element action = (Element) actions.get(i);

System.out.println("\n" + "action.path--->" + action.attributeValue("path"));

System.out.println("action.class--->" + action.attributeValue("class"));



List forwards = action.elements("forward");

for(int j=0;j<forwards.size();j++){

Element forward = (Element) forwards.get(j);

System.out.println("forward.name--->" + forward.attributeValue("name"));

System.out.println("forward.url--->" + forward.attributeValue("url"));

}

}

} catch (DocumentException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

}

<!--xml文件-->

<?

xml version="1.0" encoding="UTF-8"?> 

<actions>

<action path="/chen" class="com.demo.testCHEN">

<forward name="success" url="xiao-chen"/>

<forward name="fail" url="da-chen"/>

</action>

<action path="/bei" class="com.demo.testBEI">

<forward name="success" url="xiao-bei"/>

<forward name="fail" url="da-bei"/>

</action>

</actions>

执行结果:

action.path--->/chen

action.class--->com.demo.testCHEN

forward.name--->success

forward.url--->xiao-chen

forward.name--->fail

forward.url--->da-chen





action.path--->/bei

action.class--->com.demo.testBEI

forward.name--->success

forward.url--->xiao-bei

forward.name--->fail

forward.url--->da-bei

最新文章

  1. svn中第一次check out working copy项目下来出现 ld: library not found for -lcrypto clang: error: linker command failed with exit code 1 (use -v to see invocation)
  2. Try to write a script to send e-mail but failed
  3. SQLite中文排序
  4. 用一条sql语句显示数据百分比并加百分号
  5. EntityFramework Core 学习笔记 —— 包含与排除属性
  6. csharp:Compare two DataTables to rows in one but not the other
  7. $(document).height()、$(&quot;body&quot;).height()、$(window).height()区别和联系
  8. matlab mex入门简介
  9. SAS软件的使用和统计学分析的初步介绍
  10. Oracle dblink 使用详解
  11. 深入理解yield(转)
  12. mybatis学习笔记(五) -- maven+spring+mybatis从零开始搭建整合详细过程(附demo和搭建过程遇到的问题解决方法)
  13. LNMP搭建04 -- 配置Nginx支持PHP
  14. 微信小程序入门三实战
  15. BZOJ.4299.Codechef FRBSUM(主席树)
  16. 洛谷P3295 萌萌哒 并查集 + ST表
  17. MeshLab显示纹理贴图
  18. appium+python自动化测试
  19. python get请求
  20. C# asp.net 抓取需要登录的网页内容 抓取asp.net登录验证的网站

热门文章

  1. hdu 5637 Transform 最短路
  2. scrapy中运行爬虫时出现twisted critical unhandled error错误
  3. CSS自学笔记(3):CSS选择器
  4. .net mvc下的Areas和小写Url
  5. Hibernate get 和load的区别
  6. nfs nobody,nobody 需要在nfs客户端修改从nfs服务器端共享过来的目录怎么办?
  7. 如何阅读mysql源码
  8. arduino循迹小车
  9. 茴香豆的第五种写法---设置ExpandableListView系统自带图标按下效果
  10. SQL SERVER 2000/2005/2008数据库数据迁移到Oracle 10G细述