易截截图软件、单文件、免安装、纯绿色、仅160KB

JAVA 解析 XML

XML文件时很多项目经常使用的配置或者其他用途的文件格式,解析xml文件格式的开发包也很多,本文主要使用java自带的DOM解析包。本文以一个实际例子来讲述解析xml文件的过程。
目标:解析这样一个XML文件
employees.xml
=======内容开始========
<?xml version="1.0" encoding="UTF-8"?>
<Personnel>
  <Employee type="permanent">
        <Name>Seagull</Name>
        <Id>3674</Id>
        <Age>34</Age>
   </Employee>
  <Employee type="contract">
        <Name>Robin</Name>
        <Id>3675</Id>
        <Age>25</Age>
    </Employee>
  <Employee type="permanent">
        <Name>Crow</Name>
        <Id>3676</Id>
        <Age>28</Age>
    </Employee>
</Personnel>
=======内容结束========
目标是:输出如下内容
Employee Details - Name:Seagull, Type:permanent, Id:3674, Age:34.
Employee Details - Name:Robin, Type:contract, Id:3675, Age:25.
Employee Details - Name:Crow, Type:permanent, Id:3676, Age:28.
主要步骤
1,
Get a document builder using document builder factory and parse the xml
file to create a DOM object

Get a list of employee elements from the DOM

For each employee element get the id, name, age and type. Create an
employee value object and add it to the list.

At the end iterate through the list and print the employees to verify we
parsed it right.
a) 获取document builder
public void parseXmlFile(){
//get the factory
DocumentBuilderFactory dbf = DocumentBu


相关文档:

JAVA定时执行任务的三种方法

JAVA定时执行任务的三种方法 
1) java.util.Timer
这个方法应该是最常用的,不过这个方法需要手工启动你的任务:
Timer timer=new Timer();
timer.schedule(new ListByDayTimerTask(),10000,86400000);
这里的ListByDayTimerTask类必须extends TimerTask里面的run()方法。
2) ServletContextListener
这个方法 ......

Java异常处理及异常机制介绍

一,什么是异常
      当出现程序无法控制的外部环境问题(用户提供的文件不存在,文件内容损坏,网络不可用...)时,JAVA就会用异常对象来描述。
JAVA中用2种方法处理异常:
1.在发生异常的地方直接处理;
2.将异常抛给调用者,让调用者处理。
JAVA异常可分为3种:
  (1)检查性异常:jav ......

Java文件操作大全(五)

34.读取ini文件属性
//import java.io.*;
//import java.util.*;
//import java.util.regex.*; 
//private HashMap configMap=null;
private Map<String, Serializable> configMap=null;
String %%2=null;
if (configMap == null)&n ......

java 克隆 一个model

  AddressModel md = (AddressModel) getModel(AddressModel.class, request);
  ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); 
  ObjectOutputStream out = new ObjectOutputStream(byteOut); 
  out.writeObject(md); 
  ByteArra ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号