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

Java xml 解析的更多相关文章

  1. Java XML解析工具 dom4j介绍及使用实例

    Java XML解析工具 dom4j介绍及使用实例 dom4j介绍 dom4j的项目地址:http://sourceforge.net/projects/dom4j/?source=directory ...

  2. Java XML解析器

    使用Apache Xerces解析XML文档 一.技术概述 在用Java解析XML时候,一般都使用现成XML解析器来完成,自己编码解析是一件很棘手的问题,对程序员要求很高,一般也没有专业厂商或者开源组 ...

  3. XML概念定义以及如何定义xml文件编写约束条件java解析xml DTD XML Schema JAXP java xml解析 dom4j 解析 xpath dom sax

    本文主要涉及:xml概念描述,xml的约束文件,dtd,xsd文件的定义使用,如何在xml中引用xsd文件,如何使用java解析xml,解析xml方式dom sax,dom4j解析xml文件 XML来 ...

  4. Java数据库编程及Java XML解析技术

    1.JDBC概述 A.  什么是JDBC? Java DataBase Connectivity:是一种用于执行SQL语句的Java API,它由一组用Java语言编写的类和接口组成.通过这些类和接口 ...

  5. java xml解析方式(DOM、SAX、JDOM、DOM4J)

    XML值可扩展标记语言,是用来传输和存储数据的. XMl的特定: XMl文档必须包含根元素.该元素是所有其他元素的父元素.XML文档中的元素形成了一颗文档树,树中的每个元素都可存在子元素. 所有XML ...

  6. java XML解析

    package com.kpsh.myself; import java.io.File;import java.io.FileInputStream;import java.util.List; i ...

  7. java XML解析成Map

    1.需要解析的文件.xml <?xml version="1.0" encoding="UTF-8"?> <request> <r ...

  8. Java -- XML解析工具dom4j

    前言 XML现已成为一种通用的数据交流方式,它的平台无关性.语言无关性.系统无关性.给数据集成与交互带来了极大的方便,对于XML的解析有四种方式:DOM生成和解析XML文档,SAX生成和解析XML文件 ...

  9. 大数据之路week04--day05(java XML解析)

    java解析XML的四种方式: XML是一种通用的数据交换格式,它的平台无关性.语言无关性.系统无关性.给数据集成与交互带来了极大的方便.XML在不同的语言环境中解析方式都是一样的,只不过实现的语法不 ...

随机推荐

  1. VR大时代-全景智慧城市搭建是一个任重而道远的任务

    全景智慧城市搭建是一个任重而道远的任务,但是也促进了实体市场的蓬勃发展与进步.VR技术改变了人们以往的娱乐方式,而全景智慧城市将会彻底改变人们的生活习惯.VR是未来的计算平台,更是人力发展历史中,技术 ...

  2. sh脚本异常,binsh^M bad interpreter No such file or directory

    错误 在Linux中执行.sh脚本,出现如下异常 /bin/sh^M: bad interpreter: No such file or directory 原因 在windows系统中编辑的.sh文 ...

  3. kafka 自定义分区器

    package cn.xiaojf.kafka.producer; import org.apache.kafka.clients.producer.Partitioner; import org.a ...

  4. AbstractHandlerMapping解读

    一.AbstractHandlerMapping简介 AbstractHandlerMapping是HandlerMapping的抽象实现,所有的HandlerMapping都继承自AbstractH ...

  5. 点评阿里JAVA手册之MySQL数据库 (建表规约、索引规约、SQL语句、ORM映射)

    下载原版阿里JAVA开发手册  [阿里巴巴Java开发手册v1.2.0] 本文主要是对照阿里开发手册,注释自己在工作中运用情况. 本文内容:MySQL数据库 (建表规约.索引规约.SQL语句.ORM映 ...

  6. Windows下用Composer引入官方GitHub扩展包

    Windows下用Composer引入官方GitHub扩展包 1. 当你打开威武RC4版本的链接的时候,往下拉你可以看到这个,然后你要做的就是想到,百度Composer,看看是个什么鬼,别想太多,跟着 ...

  7. Android Apk的反编译和加密

    这几天在上海出差,忙里偷闲学习了一下Apk的反编译工具的基本使用.下面就简单介绍一下如何将我们从网上下载的Apk文件进行反编译得到我们想要获得的资源文件和源码. Android的应用程序APK文件说到 ...

  8. 影响国内WinCE7发展的最大障碍是没有D版下载

    WinCE红火的时代已经过去,做嵌入式系统时考虑WinCE的越来越少,网络上相关文章也是越来越少. 但真正用过WinCE的应该有体会,它集成了文件系统,tcp/ip,GUI系统,usb驱动,就这些,你 ...

  9. 浅谈如何保证discuz插件安全

    1.非直接执行程序请加上 if(!defined('IN_DISCUZ')) { exit('Access Denied'); } 2.记得过滤 比如说uid等id需要intval过滤,避免溢出    ...

  10. python_adb 图形界面获取app测试数据,并展示部分测试报告v1.0版本

    想到平时想用adb 我就忍不住去翻开笔记,脑子记不住,不好使,不知道大家有没有这个想法呢,不管你有没有,反正我有了,ttm,太烦人了,于是乎,我就开始给自己写个需求文档, 这就是我写的,产品需求,合理 ...