- 浏览: 316373 次
- 性别:
- 来自: 长沙
文章分类
最新评论
-
完善自我:
支持一下!
揭秘IT人才特点:中美印日四国程序员比较 -
悲剧了:
好文,看玩thinking in java的提到的异常处理,看 ...
高效的Java异常处理框架(转) -
yin_bp:
开源框架bbossgroups页支持组件异步方法调用哦,详情请 ...
Spring 3中异步方法调用 -
flyjava:
sun的悲哀
Apache怒了,威胁说要离开JCP
The StAX API exposes methods for iterative, event-based processing of XML documents. XML documents are treated as a filtered series of events, and infoset states can be stored in a procedural fashion. Moreover, unlike SAX, the StAX API is bidirectional, enabling both reading and writing of XML documents. The StAX API is really two distinct API sets: a
cursor
API and an
iterator
API. These two API sets explained in greater detail later in this chapter, but their main features are briefly described below. As the name implies, the StAX
cursor
API represents a cursor with which you can walk an XML document from beginning to end. This cursor can point to one thing at a time, and always moves forward, never backward, usually one infoset element at a time. The two main cursor interfaces are
You can call methods on
The cursor API mirrors SAX in many ways. For example, methods are available for directly accessing string and character information, and integer indexes can be used to access attribute and namespace information. As with SAX, the cursor API methods return XML information as strings, which minimizes object allocation requirements. The StAX
iterator
API represents an XML document stream as a set of discrete event objects. These events are pulled by the application and provided by the parser in the order in which they are read in the source XML document. The base iterator interface is called
Similarly, on the output side of the iterator API, you have: Table 3-2
lists the thirteen
Note that the
As an example of how the event iterator API maps an XML stream, consider the following XML document: This document would be parsed into eighteen primary and secondary events, as shown below. Note that secondary events, shown in curly braces ( There are several important things to note in the above example: It is reasonable to ask at this point, "What API should I choose? Should I create instances of
The authors of the StAX specification targeted three types of developers: Given these wide-ranging development categories, the StAX authors felt it was more useful to define two small, efficient APIs rather than overloading one larger and necessarily more complex API. Before choosing between the cursor and iterator APIs, you should note a few things that you can do with the iterator API that you cannot do with cursor API: Similarly, keep some general recommendations in mind when making your choice:StAX API
Cursor API
XMLStreamReader
and
XMLStreamWriter
.
XMLStreamReader
includes accessor methods for all possible information retrievable from the XML Information model, including document encoding, element names, attributes, namespaces, text nodes, start tags, comments, processing instructions, document boundaries, and so forth; for example:public interface XMLStreamReader {
public int next() throws XMLStreamException;
public boolean hasNext() throws XMLStreamException;
public String getText();
public String getLocalName();
public String getNamespaceURI();
// ... other methods not shown
}
XMLStreamReader
, such as
getText
and
getName
, to get data at the current cursor location.
XMLStreamWriter
provides methods that correspond to
StartElement
and
EndElement
event types; for example:public interface XMLStreamWriter {
public void writeStartElement(String localName) \
throws XMLStreamException;
public void writeEndElement() \
throws XMLStreamException;
public void writeCharacters(String text) \
throws XMLStreamException;
// ... other methods not shown
}
Iterator API
XMLEvent
, and there are subinterfaces for each event type listed in
Table 3-2
, below. The primary parser interface for reading iterator events is
XMLEventReader
, and the primary interface for writing iterator events is
XMLEventWriter
. The
XMLEventReader
interface contains five methods, the most important of which is
nextEvent()
, which returns the next event in an XML stream.XMLEventReader
implements
java.util.Iterator
, which means that returns from
XMLEventReader
can be cached or passed into routines that can work with the standard Java Iterator; for example:public interface XMLEventReader extends Iterator {
public XMLEvent nextEvent() throws XMLStreamException;
public boolean hasNext();
public XMLEvent peek() throws XMLStreamException;
...
}
public interface XMLEventWriter {
public void flush() throws XMLStreamException;
public void close() throws XMLStreamException;
public void add(XMLEvent e) throws XMLStreamException;
public void add(Attribute attribute) \
throws XMLStreamException;
...
}
Iterator Event Types
XMLEvent
types defined in the event iterator API.DTD
,
EntityDeclaration
,
EntityReference
,
NotationDeclaration
, and
ProcessingInstruction
events are only created if the document being processed contains a DTD.Sample Event Mapping
<?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>
{}
), are typically accessed from a primary event rather than directly.
StartElement
has a corresponding
EndElement
, even for empty elements.Attribute
events are treated as secondary events, and are accessed from their corresponding
StartElement
event.Attribute
events,
Namespace
events are treated as secondary, but appear twice and are accessible twice in the event stream, first from their corresponding
StartElement
and then from their corresponding
EndElement
.Character
events are specified for all elements, even if those elements have no character data. Similarly,
Character
events can be split across events.javax.xml.namespace.NamespaceContext
interface, and can be accessed by namespace prefix or URI.Choosing Between Cursor and Iterator APIs
XMLStreamReader
or
XMLEventReader
? Why are there two kinds of APIs anyway?"Development Goals
Comparing Cursor and Iterator APIs
XMLEvent
subclasses are immutable, and can be used in arrays, lists, and maps, and can be passed through your applications even after the parser has moved on to subsequent events.XMLEvent
that are either completely new information items or extensions of existing items but with additional methods.
发表评论
-
Java包导入机制的解析总结
2010-12-01 20:50 1192java中有两种包的导 ... -
提高JSP和SERVLET性能的七大绝招
2010-11-30 10:02 1156本文讲述了调整JSP和servlet的一些非常实用的方法,它可 ... -
使用future实现内置异步API
2010-11-16 15:52 1052当设计并发策略时,要将 "what做什么" ... -
asyn4j—java 异步方法调用框架
2010-11-16 15:36 2091asyn4j 是一个java异步方法调用框架,包括 ... -
关于 Java 性能监控您不知道的 5 件事,第 2 部分
2010-11-15 11:02 767全功能内置分析器,如 JConsole 和 VisualVM ... -
关于 Java 性能监控您不知道的 5 件事,第 1 部分
2010-11-15 10:13 799当应用程序性能受到损 ... -
jsp生成静态页(jsp+servlet+xml)
2010-11-08 17:38 1324package ningxia.bl.admin.conten ... -
动态JSP页生成静态HTML
2010-11-08 17:31 1042具体实现: 利用 Filte ... -
深入Java核心 Java中多态的实现机制
2010-10-23 19:22 1215多态性是面向对 ... -
八个改善Java遗留系统的技巧
2010-10-16 10:04 802你没看错,就是这个题目:即使是Java系统也会变成“遗留”系统 ... -
IBM加入OpenJDK,和Oracle一道推动Java发展
2010-10-14 15:14 1656Oracle(新闻发布 )和IBM(新闻发布 )昨天联合宣 ... -
用 Slice 扩展 OpenJPA 应用程序
2010-10-11 09:43 1150简介 Slice 将 OpenJPA 扩展用 ... -
常用 Java Profiling 工具的分析与比较
2010-09-26 17:10 1277简介: 在 Java 程序的 ... -
在Spring基础上实现自己的异常处理框架
2010-09-26 15:03 0应用项目大致的体系结 ... -
高效的Java异常处理框架(转)
2010-09-26 14:53 1529摘要:本文从Java异常最基本的概念、语法开始讲述了Jav ... -
关于 Java Scripting API 您不知道的 5 件事
2010-09-25 16:53 939现在,许多 Java 开发人员都喜欢在 Java 平台中使用脚 ... -
关于 Java Database Connectivity 您不知道的 5 件事
2010-09-25 15:32 795目前,许多开发人员把 ... -
综述:字符串到Java对象转换的工具库(转)
2010-09-20 21:41 1113原文:http://www.infoq.com/cn/news ...
相关推荐
STAX(Streaming API for XML)是Java平台上的一个XML处理API,它提供了对XML文档的事件驱动解析。与DOM(Document Object Model)不同,STAX不是加载整个XML文档到内存中形成一个树形结构,而是通过事件(如开始...
**STAX API 1.0-2:XML处理的关键组件** STAX,全称为Streaming API for XML,是一种用于处理XML的Java API。STAX提供了一种流式处理XML文档的方法,与DOM(Document Object Model)相比,它更加高效且内存占用更低...
`stax-api.jar`是Java中用于处理XML流的STAX(Streaming API for XML)的API接口库,它提供了与XML数据交互的一套标准化接口。 STAX(Streaming API for XML)是一种低级别的XML解析方法,相比DOM(Document Object...
STAX(Streaming API for XML)是一种用于处理XML的Java API,它提供了事件驱动的解析方式,使得开发者可以高效地读取和写入XML文档。在Java世界中,STAX提供了比DOM(Document Object Model)更高效的处理XML的方式...
STAX(Streaming API for XML)是Java平台上的一个XML处理API,它提供了高效且灵活的方式来读取和写入XML文档。STAX的核心理念是事件驱动,即解析XML时,每遇到一个XML元素或属性,都会触发一个相应的事件,程序通过...
Streaming API for XML(StAX)是Java平台上的一个高级XML处理API,它提供了对XML文档的高效、低级别的访问方式。"stax2-api-3.1.1.jar"是一个Java库,主要用于XML解析,特别是采用了StAX 2.0规范的实现。这个jar...
赠送jar包:stax2-api-3.1.4.jar; 赠送原API文档:stax2-api-3.1.4-javadoc.jar; 赠送源代码:stax2-api-3.1.4-sources.jar; 赠送Maven依赖信息文件:stax2-api-3.1.4.pom; 包含翻译后的API文档:stax2-api-...
Java EE, Android读写XML,POI使用
JSR 173 API的核心接口是`javax.xml.transform.stax.StAXSource`和`javax.xml.transform.stax.StAXResult`,它们分别用于创建XML源和结果。这两个接口与Java的StAX(Streaming API for XML)结合,使得开发者能够...
实现了特殊的XML验证,一般来说使用SAXParser来读入XML文件再进行验证,但是这里使 用了边写边验证的功能,如果是...是Stax2 API提供的功能 java转换json或xml,支持Java和Json格式的互转,同时也支持Java和XML的互转
用来解析XML文件的jar包。Streaming API for XML (StAX) 的基于事件迭代器 API 无论在性能还是在可用性上都有其他 XML 处理方法所不及的独到之处。使用前请先解压
标题中的"backport-util-concurrent-3.1.jar"和"geronimo-stax-api_1.0_spec-1.0.1.jar"是两个Java库文件,它们在解决Eclipse Axis2 Codegen插件报错问题时起着关键作用。Axis2是一个流行的Web服务框架,而Codegen...
- **XMLStreamReader/Writer的扩展**:除了标准STAX API提供的功能,STAX EX还提供了一些扩展API,如XMLStreamReader的peek()方法,允许开发者预览下一个事件,以及XMLStreamWriter的writeCharacters()方法的变体,...
stax2-api-3.1.1-sources.jar文件,下载使用,用来解析XML文件的jar包。Streaming API for XML (StAX) 的基于事件迭代器 API 无论在性能还是在可用性上都有其他 XML 处理方法所不及的独到之处。
3. stax-api-1.0.1:STAX (Streaming API for XML) 是一种用于解析和生成XML的Java API,它允许程序以事件驱动的方式处理XML流。在Apache POI中,STAX API被用来高效地读取和写入大型XML文件,比如XLSX和DOCX格式的...
Stax2 API是标准 API(“用于Xml处理的STandard Api”)的扩展,它是JDK 6中添加的JDK的pull-parser API。 地位 支持 Stax2 API通过以下Stax XML实现来本地实现: (面向性能,也是非阻塞/异步的) (Java平台上...
geronimo-stax-api_1.0_spec-1.0.jar
【标题】"jsr173_1.0_api.jar"是Java标准版的一个扩展,全称为Java Specification Request 173(JSR 173),它定义了Java编程语言对XML Streaming API(StAX - Streaming API for XML)的支持。这个API允许开发者以...
赠送jar包:stax2-api-3.1.4.jar; 赠送原API文档:stax2-api-3.1.4-javadoc.jar; 赠送源代码:stax2-api-3.1.4-sources.jar; 赠送Maven依赖信息文件:stax2-api-3.1.4.pom; 包含翻译后的API文档:stax2-api-...