Chinaunix首页 | 论坛 | 博客
  • 博客访问: 160770
  • 博文数量: 27
  • 博客积分: 1472
  • 博客等级: 上尉
  • 技术积分: 275
  • 用 户 组: 普通用户
  • 注册时间: 2007-03-29 12:25
文章分类
文章存档

2010年(2)

2008年(6)

2007年(19)

最近访客

分类: Java

2007-06-13 19:48:19

JAVA解析XML文件的四种方法之四 -> DOM4J
 
 
JAVA Bean:
 
 
 package com.test;

import java.io.*;
import java.util.*;
import org.dom4j.*;
import org.dom4j.io.*;

public class MyXMLReader {

 public static void main(String arge[]) {
  long lasting = System.currentTimeMillis();
  try {
   File f = new File("data_10k.xml");
   SAXReader reader = new SAXReader();
   Document doc = reader.read(f);
   Element root = doc.getRootElement();
   Element foo;
   for (Iterator i = root.elementIterator("VALUE"); i.hasNext();) {
    foo = (Element) i.next();
    System.out.print("车牌号码:" + foo.elementText("NO"));
    System.out.println(" 车主地址:" + foo.elementText("ADDR"));
   }
  } catch (Exception e) {
   e.printStackTrace();
  }
  System.out.println("运行时间:" + (System.currentTimeMillis() - lasting) + " 毫秒");
 }
}
 
测试结果如下:

10k消耗时间:109 78 109 31
100k消耗时间:297 359 172 312
1000k消耗时间:2281 2359 2344 2469
10000k消耗时间:20938 19922 20031 21078

阅读(1727) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~