1.
XML框架结构
Java SE 6 平台提供的 XML 处理主要包括两个功能:XML 处理(JAXP,Java Architecture XML Processing)和 XML 绑定(JAXB,Java Architecture XML Binding)。
JAXP 包括 SAX 框架 —— 遍历元素,做出处理;DOM 框架 —— 构造 XML 文件的树形表示;StAX 框架 —— 拖拽方式的解析;XSLT 框架 —— 将 XML 数据转换成其他格式。JAXB 则是负责将 XML 文件和 Java 对象绑定,在新版 JDK 中,被大量的使用在 Web 服务技术中。
目前的Java 操作xml的类库主要有:http://www.open-open.com/31.htm
2. stax解析
Ierator Event Types
Table 3-2 lists the thirteen XMLEvent
types defined in the event iterator API.
Sample Event Mapping
As an example of how the event iterator API maps an XML stream, consider the following XML document:
<?xml version="1.0"?> <BookCatalogue xmlns="http://www.publishing.org"> <Book> <Title>Yogasana Vijnana: the Science of Yoga</Title> <ISBN>81-40-34319-4</ISBN> <Cost currency="INR">11.50</Cost> </Book> </BookCatalogue>
This document would be parsed into eighteen primary and secondary events, as shown below. Note that secondary events, shown in curly braces ({}
), are typically accessed from a primary event rather than directly.
Table 3-3 Sample Iterator API Event Mapping |
||
# |
Element/Attribute |
Event |
1 |
version="1.0" |
StartDocument |
2 |
isCData = false |
Characters |
3 |
qname = BookCatalogue:http://www.publishing.org |
StartElement |
4 |
qname = Book |
StartElement |
5 |
qname = Title |
StartElement |
6 |
isCData = false |
Characters |
7 |
qname = Title |
EndElement |
8 |
qname = ISBN |
StartElement |
9 |
isCData = false data = "81-40-34319-4 " IsWhiteSpace = false |
Characters |
10 |
qname = ISBN |
EndElement |
11 |
qname = Cost |
StartElement |
12 |
isCData = false |
Characters |
13 |
qname = Cost |
EndElement |
14 |
isCData = false |
Characters |
15 |
qname = Book |
EndElement |
16 |
isCData = false |
Characters |
17 |
qname = BookCatalogue:http://www.publishing.org |
EndElement |
18 |
|
EndDocument |