这是xml文件
<?xml version="1.0" encoding="gbk"?>
<!DOCTYPE persons SYSTEM "person.dtd">
<persons>
<person name="jiang">
<age>11</age>
<email>element@hz.cn</email>
</person>
<person name="hong">
<age>22</age>
<email>rossi789@163.com</email>
</person>
<person name="bing">
<age>33</age>
<email>jianghb.jesse@yahoo.com.cn</email>
</person>
</persons>
这是DTD文件
<!DOCTYPE persons [
<!ELEMENT persons (person*)>
<!ELEMENT person (age, email)>
<!ALLLIST person name CDATA "null">
<!ELEMENT age (#PCDATA)>
<!ELEMENT email (#PCDATA)>
]>
这是程序代码
/**
* @project jiangHB_j2se
* @file_name ReadCfg.java
*/
package ch0;
import java.util.*;
import java.io.*;
/**
* @author jhb
* @version 1.0
* @create_on Sep 23, 2007 3:17:35 PM
*/
public final class ReadCfg {
public static void main(String[] args) {
Properties file = new Properties();
try {
file.loadFromXML(new FileInputStream("gateway.xml"));
file.list(System.out);
} catch (IOException e) {
e.printStackTrace();
}
}
}