SAX - DefaultHandler
org.xml.sax.helpers.DefaultHandler 实现了 org.xml.sax.EntityResolver、org.xml.sax.DTDHandler、org.xml.sax.ContentHandler 和 org.xml.sax.ErrorHandler,并提供了默认的实现方法(不做任何操作)。
ContentHandler
setDocumentLocator
Receive an object for locating the origin of SAX document events.
SAX parsers are strongly encouraged (though not absolutely required) to supply a locator: if it does so, it must supply the locator to the application by invoking this method before invoking any of the other methods in the ContentHandler interface.
The locator allows the application to determine the end position of any document-related event, even if the parser is not reporting an error. Typically, the application will use this information for reporting its own errors (such as character content that does not match an application's business rules). The information returned by the locator is probably not sufficient for use with a search engine.
Note that the locator will return correct information only during the invocation SAX event callbacks after startDocument returns and before endDocument is called. The application should not attempt to use it at any other time.
startDocument()
Receive notification of the beginning of a document. The SAX parser will invoke this method only once, before any other event callbacks (except for setDocumentLocator).
endDocument()
Receive notification of the end of a document.
There is an apparent contradiction between the documentation for this method and the documentation for ErrorHandler.fatalError(org.xml.sax.SAXParseException). Until this ambiguity is resolved in a future major release, clients should make no assumptions about whether endDocument() will or will not be invoked when the parser has reported a fatalError() or thrown an exception.
The SAX parser will invoke this method only once, and it will be the last method invoked during the parse. The parser shall not invoke this method until it has either abandoned parsing (because of an unrecoverable error) or reached the end of input.
startPrefixMapping
Begin the scope of a prefix-URI Namespace mapping.
The information from this event is not necessary for normal Namespace processing: the SAX XML reader will automatically replace prefixes for element and attribute names when the http://xml.org/sax/features/namespaces feature is true (the default).
There are cases, however, when applications need to use prefixes in character data or in attribute values, where they cannot safely be expanded automatically; the start/endPrefixMapping event supplies the information to the application to expand prefixes in those contexts itself, if necessary.
Note that start/endPrefixMapping events are not guaranteed to be properly nested relative to each other: all startPrefixMapping events will occur immediately before the corresponding startElement event, and all endPrefixMapping events will occur immediately after the corresponding endElement event, but their order is not otherwise guaranteed.
There should never be start/endPrefixMapping events for the "xml" prefix, since it is predeclared and immutable.
endPrefixMapping
End the scope of a prefix-URI mapping.
See startPrefixMapping for details. These events will always occur immediately after the corresponding endElement event, but the order of endPrefixMapping events is not otherwise guaranteed.
startElement
Receive notification of the beginning of an element.
The Parser will invoke this method at the beginning of every element in the XML document; there will be a corresponding endElement event for every startElement event (even when the element is empty). All of the element's content will be reported, in order, before the corresponding endElement event.
This event allows up to three name components for each element:
- the Namespace URI;
- the local name; and
- the qualified (prefixed) name.
Any or all of these may be provided, depending on the values of the http://xml.org/sax/features/namespaces and the http://xml.org/sax/features/namespace-prefixesproperties:
- the Namespace URI and local name are required when the namespaces property is true (the default), and are optional when the namespaces property is false (if one is specified, both must be);
- the qualified name is required when the namespace-prefixes property is true, and is optional when the namespace-prefixes property is false (the default).
Note that the attribute list provided will contain only attributes with explicit values (specified or defaulted): #IMPLIED attributes will be omitted. The attribute list will contain attributes used for Namespace declarations (xmlns* attributes) only if the http://xml.org/sax/features/namespace-prefixes
property is true (it is false by default, and support for a true value is optional).
Like characters(), attribute values may have characters that need more than one char value.
endElement
Receive notification of the end of an element.
The SAX parser will invoke this method at the end of every element in the XML document; there will be a corresponding startElement event for every endElement event (even when the element is empty).
For information on the names, see startElement.
characters
Receive notification of character data.
The Parser will call this method to report each chunk of character data. SAX parsers may return all contiguous character data in a single chunk, or they may split it into several chunks; however, all of the characters in any single event must come from the same external entity so that the Locator provides useful information.
The application must not attempt to read from the array outside of the specified range.
Individual characters may consist of more than one Java char value. There are two important cases where this happens, because characters can't be represented in just sixteen bits. In one case, characters are represented in a Surrogate Pair, using two special Unicode values. Such characters are in the so-called "Astral Planes", with a code point above U+FFFF. A second case involves composite characters, such as a base character combining with one or more accent characters.
Your code should not assume that algorithms using char-at-a-time idioms will be working in character units; in some cases they will split characters. This is relevant wherever XML permits arbitrary characters, such as attribute values, processing instruction data, and comments as well as in data reported from this method. It's also generally relevant whenever Java code manipulates internationalized text; the issue isn't unique to XML.
Note that some parsers will report whitespace in element content using the ignorableWhitespace method rather than this one (validating parsers must do so).
ignorableWhitespace
Receive notification of ignorable whitespace in element content.
Validating Parsers must use this method to report each chunk of whitespace in element content (see the W3C XML 1.0 recommendation, section 2.10): non-validating parsers may also use this method if they are capable of parsing and using content models.
SAX parsers may return all contiguous whitespace in a single chunk, or they may split it into several chunks; however, all of the characters in any single event must come from the same external entity, so that the Locator provides useful information.
The application must not attempt to read from the array outside of the specified range.
processingInstruction
Receive notification of a processing instruction.
The Parser will invoke this method once for each processing instruction found: note that processing instructions may occur before or after the main document element.
A SAX parser must never report an XML declaration (XML 1.0, section 2.8) or a text declaration (XML 1.0, section 4.3.1) using this method.
Like characters(), processing instruction data may have characters that need more than one char value.
skippedEntity
Receive notification of a skipped entity. This is not called for entity references within markup constructs such as element start tags or markup declarations. (The XML recommendation requires reporting skipped external entities. SAX also reports internal entity expansion/non-expansion, except within markup constructs.)
The Parser will invoke this method each time the entity is skipped. Non-validating processors may skip entities if they have not seen the declarations (because, for example, the entity was declared in an external DTD subset). All processors may skip external entities, depending on the values of thehttp://xml.org/sax/features/external-general-entities
and the http://xml.org/sax/features/external-parameter-entities
properties.
ErrorHandler
warning
Receive notification of a warning.
SAX parsers will use this method to report conditions that are not errors or fatal errors as defined by the XML recommendation. The default behaviour is to take no action.
The SAX parser must continue to provide normal parsing events after invoking this method: it should still be possible for the application to process the document through to the end.
Filters may use this method to report other, non-XML warnings as well.
error
Receive notification of a recoverable error.
This corresponds to the definition of "error" in section 1.2 of the W3C XML 1.0 Recommendation. For example, a validating parser would use this callback to report the violation of a validity constraint. The default behaviour is to take no action.
The SAX parser must continue to provide normal parsing events after invoking this method: it should still be possible for the application to process the document through to the end. If the application cannot do so, then the parser should report a fatal error even if the XML recommendation does not require it to do so.
Filters may use this method to report other, non-XML errors as well.
fatalError
Receive notification of a non-recoverable error.
There is an apparent contradiction between the documentation for this method and the documentation for ContentHandler.endDocument(). Until this ambiguity is resolved in a future major release, clients should make no assumptions about whether endDocument() will or will not be invoked when the parser has reported a fatalError() or thrown an exception.
This corresponds to the definition of "fatal error" in section 1.2 of the W3C XML 1.0 Recommendation. For example, a parser would use this callback to report the violation of a well-formedness constraint.
The application must assume that the document is unusable after the parser has invoked this method, and should continue (if at all) only for the sake of collecting additional error messages: in fact, SAX parsers are free to stop reporting any other events once this method has been invoked.
SAX - DefaultHandler的更多相关文章
- Java SAX DefaultHandler
The org.xml.sax.helpers.DefaultHandler class is the base class for "listeners" in SAX 2.0. ...
- sax解析xml文件的DefaultHandler处理类
一千年的时光,我无数次掀起岁月的帷幔,只为和你,在某一个平静如水的日子相遇,然后相识,倾情一生,缱绻一世,好美的散文,好吧,我情愿把这个“你”当作android:),使用sax解析xml文件是我见到过 ...
- Android之SAX解析XML
一.SAX解析方法介绍 SAX(Simple API for XML)是一个解析速度快并且占用内存少的XML解析器,非常适合用于Android等移动设备. SAX解析器是一种基于事件的解析器,事件驱动 ...
- XML技术之SAX解析器
1.解析XML文件有三种解析方法:DOM SAX DOM4J. 2.首先SAX解析技术只能读取XML文档中的数据信息,不能对其文档中的数据进行添加,删除,修改操作:这就是SAX解析技术的一个缺陷. 3 ...
- 四种解析和创建方式(DOM,SAX,DOM4J,JDOM)
一.先导入jar包 DOM基于树形,SAX基于事件,DOM4J和JDOM基于底层API 二.代码如下 1 package com.sxt.test; import java.io.File; impo ...
- Android 使用pull,sax解析xml
pull解析xml文件 1.获得XmlpullParser类的引用 这里有两种方法 //解析器工厂 XmlPullParserFactory factory=XmlPullParserFactory. ...
- JAVA使用SAX解析XML文件
在我的另一篇文章(http://www.cnblogs.com/anivia/p/5849712.html)中,通过一个例子介绍了使用DOM来解析XML文件,那么本篇文章通过相同的XML文件介绍如何使 ...
- java使用sax解析xml
目的:解析xml文件,并存入mysql,并且要解析的字段能一一对应.这里解析的是微博的文件,想要利用里面的article和person_id字段. 思路: 为了能得到person_id和article ...
- XML.03-DOM和SAX解析
body,td { font-family: calibri; font-size: 10pt } XML.03-DOM和SAX解析 XML的DOM解析 解析 处理 回写 XML的SAX解析 SAX和 ...
随机推荐
- 转载 从Http到Https
转载自 http://www.cnblogs.com/silin6/p/5928503.html HTTP 当你在浏览器输入一个网址 (例如 http://tasaid.com)的时候,浏览器发起一个 ...
- CommandLine 和 Options
用到的jar包 <dependency> <groupId>commons-cli</groupId> <artifactId>commons-cli& ...
- 小谈chrome调试命令:console.log的使用
相信从事前端开发的您,一定不会陌生Mozilla五星级推荐的一款插件:firebug,它是如此强大,乃至于我们可以很方便地调试DHTML的近乎所有元素.而在它深邃的机体里,还存有一个命令:consol ...
- Navicat for mysql 11.0破解方法
Navicat for mysql破解器 首先下载破解器,然后解压至随意一个目录下.最后双击exe程序,按照提示找到你安装好的navicat for mysql文件夹下的navicat.exe程序,之 ...
- 放开Linux内核对用户进程可打开文件数和TCP连接的限制
一. 检查linux内核uname -alsb_release -a 二. 用户进程可打开文件数限制1) vim /etc/security/limits.conf* - nof ...
- 下载discuz 6 论坛的附件
前段时间我下了个python脚本把emsky的附件全部下载了,之前是因为偶然发现emsky附件不登陆也能访问,直接访问一个url就行了. 后来发现大部分discuz6的论坛都有这个bug,我想是因为d ...
- Codeforces Gym 100650B Countdown DFS
Problem B: CountdownTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/conte ...
- 架构师之路(39)---IoC框架
1 IoC理论的背景 我们都知道,在採用面向对象方法设计的软件系统中,它的底层实现都是由N个对象组成的,全部的对象通过彼此的合作,终于实现系统的业务逻辑. 图1:软件系统中耦合的对象 假设 ...
- android 自定义按钮实现 home键 和返回键
由于在自己做的东西中用到了就总结一下,自己做了测试 在一个程序运行中如果按 返回键 分别执行了 : onpause() onStop() onDestory()方法 如果点击 home键 ...
- mysql online ddl2
大家知道,互联网业务是典型的OLTP(online transaction process)应用,这种应用访问数据库的特点是大量的短事务高并发运行.因此任何限制高并发的动作都是不可接受的, ...