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.

Table 3-2 XMLEvent Types

Event Type
Description
StartDocument
Reports the beginning of a set of XML events, including encoding, XML version, and standalone properties.
StartElement
Reports the start of an element, including any attributes and namespace declarations; also provides access to the prefix, namespace URI, and local name of the start tag.
EndElement
Reports the end tag of an element. Namespaces that have gone out of scope can be recalled here if they have been explicitly set on their corresponding StartElement.
Characters
Corresponds to XML CData sections and CharacterData entities. Note that ignorable whitespace and significant whitespace are also reported as Character events.
EntityReference
Character entities can be reported as discrete events, which an application developer can then choose to resolve or pass through unresolved. By default, entities are resolved. Alternatively, if you do not want to report the entity as an event, replacement text can be substituted and reported as Characters.
ProcessingInstruction
Reports the target and data for an underlying processing instruction.
Comment
Returns the text of a comment
EndDocument
Reports the end of a set of XML events.
DTD
Reports as java.lang.String information about the DTD, if any, associated with the stream, and provides a method for returning custom objects found in the DTD.
Attribute
Attributes are generally reported as part of a StartElement event. However, there are times when it is desirable to return an attribute as a standalone Attribute event; for example, when a namespace is returned as the result of an XQuery or XPath expression.
Namespace
As with attributes, namespaces are usually reported as part of a StartElement, but there are times when it is desirable to report a namespace as a discrete Namespace event.

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
data = "\n"
IsWhiteSpace = true

Characters

3

qname = BookCatalogue:http://www.publishing.org
attributes = null
namespaces = {BookCatalogue" -> http://www.publishing.org"}

StartElement

4

qname = Book
attributes = null
namespaces = null

StartElement

5

qname = Title
attributes = null
namespaces = null

StartElement

6

isCData = false
data = "Yogasana Vijnana: the Science of Yoga\n\t"
IsWhiteSpace = false

Characters

7

qname = Title
namespaces = null

EndElement

8

qname = ISBN
attributes = null
namespaces = null

StartElement

9

isCData = false

data = "81-40-34319-4\n\t"

IsWhiteSpace = false

Characters

10

qname = ISBN
namespaces = null

EndElement

11

qname = Cost
attributes = {"currency" -> INR}
namespaces = null

StartElement

12

isCData = false
data = "11.50\n\t"
IsWhiteSpace = false

Characters

13

qname = Cost
namespaces = null

EndElement

14

isCData = false
data = "\n"
IsWhiteSpace = true

Characters

15

qname = Book
namespaces = null

EndElement

16

isCData = false
data = "\n"
IsWhiteSpace = true

Characters

17

qname = BookCatalogue:http://www.publishing.org
namespaces = {BookCatalogue" -> http://www.publishing.org"}

EndElement

18

EndDocument

最新文章

  1. bootstrap-datetimepicker 进一步跟进~~~开始时间和结束时间的样式显示
  2. Examples of MIB Variables - SNMP Tutorial
  3. echarts X轴数据显示不全问题
  4. 在ASP.MVC中使用Ajax
  5. HNOI2002
  6. 每日一九度之 题目1033:继续xxx定律
  7. 分页sql
  8. angularjs2 学习笔记(二) 组件
  9. HTML5实现在线抓拍
  10. JVM调优总结(二)-一些概念
  11. js-面试题1
  12. 今日头条- iOS客户端 启动速度优化实践
  13. Runtime的使用
  14. 关联tomcat源代码
  15. adb命令集合
  16. 2012年蓝桥杯省赛A组c++第2题(暴力求解古堡算式)
  17. cygwin ctrl+s的问题
  18. 压力测试工具ab及centos下单独安装方法 nginx和tomcat静态资源的性能测试
  19. python中的对象(三)
  20. 【Android开发】如何设计开发一款Android App

热门文章

  1. neutron flat和vxlan网络访问外网流量走向
  2. PF2.1版本总结,在设计过程中遇到的问题以及技术分享
  3. 解决相关css基础问题
  4. 新写的高仿Arcmap,要的拿去玩玩
  5. HTTP权威指南-HTTP报文
  6. shell多进程
  7. 面向对象的SOLID原则白话篇
  8. 360安全检测出的WordPress漏洞的修复方法
  9. el表达式字符串使用总结
  10. ps命令注意事项