首页>代码>java解析xml的四种方式>/xml/src/demo/MyXMLDOM4J.java
package demo;

import java.io.File;
import java.util.Iterator;

import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;


public class MyXMLDOM4J {
		public static void main(String[] args) {
			long lasting=System.currentTimeMillis();
			try {
				File f=new File("src/a.xml");
				SAXReader sr=new SAXReader();
				Document doc=sr.read(f);
				Element root=doc.getRootElement();
				Element e;
				for(Iterator i=root.elementIterator("stu");i.hasNext();){
					e=(Element)i.next();
					System.out.println("sname:"+e.elementText("sname"));
					System.out.println("sex:"+e.elementText("sex"));
					System.out.println("age:"+e.elementText("age"));
				}
					
				
			} catch (Exception e) {
				e.printStackTrace();
			}
			System.out.println("运行时间"+(System.currentTimeMillis()-lasting)+"毫秒");
		}
}
最近下载更多
1358849392  LV21 2022年11月11日
gaotieyou  LV5 2021年12月11日
tansuo阿郎  LV8 2021年2月27日
simple丶余心  LV21 2020年9月16日
0312wangchen  LV26 2020年4月26日
3969138  LV15 2019年9月23日
cc900118  LV17 2018年3月7日
JoyKinG  LV19 2017年11月28日
zeng8750  LV2 2017年10月29日
元芳你怎么看  LV15 2016年12月26日
最近浏览更多
月之氏族  LV23 2024年4月22日
wbbhappy  LV13 2024年1月11日
1358849392  LV21 2022年11月11日
林间听风  LV10 2022年8月17日
我是helloworld  LV23 2022年6月2日
gaotieyou  LV5 2021年12月11日
shiopaaa  LV13 2021年8月23日
329512801  LV28 2021年7月7日
张洪  LV1 2021年7月1日
Hachi6  LV13 2021年5月10日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友