XML文档结构
XML文档应当以一个文档头开始,例如:
<?xml version="1.0"?>
或者
<?xml version="1.0" ecconding="UTF-8"?>
文档头后通常是文档类型定义(Document Type Definition,DTD)
<!DOCTYPE web-app PUBLIC
"-//Sun Microystems.Inc.//DTD Web Application 2.2//EN"
"http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">
<?xml version="1.0"?>
<!DOCTYPE configuration . . .>
<configuration>
<title>
<font>
<name>Helvetica</name>
<size>36</size>
</font>
</title>
</configuration>
解析XML文档
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstabne();
DocumentBuilder builder = factory.newDocumentBuilder();
File f = ..
Document doc = build.parse(f);