public abstract class SAXParser
extends Object
| java.lang.Object | |
| javax.xml.parsers.SAXParser | |
定义包装XMLReader实现类的API。 在JAXP 1.0中,这个类包装了Parser接口,但是该接口被替换为XMLReader 。 为了便于过渡,这个类继续支持相同的名称和接口以及支持新方法。 这个类的一个实例可以从newSAXParser()方法中获得。 一旦获得此类的实例,就可以从各种输入源分析XML。 这些输入源是InputStreams,Files,URLs和SAX InputSources。
此静态方法基于系统属性设置创建新的工厂实例,如果没有定义属性,则使用平台默认值。
控制要创建哪个Factory实现的系统属性被命名为"javax.xml.parsers.SAXParserFactory" 。 该属性命名一个类,该类是此抽象类的具体子类。 如果没有定义属性,将使用平台默认值。
HandlerBase or the
DefaultHandler are called.
包装底层实现的这个类的实现可以考虑使用 ParserAdapter类来初始化它们的SAX1实现,使其在这个修订的类下工作。
Protected constructors |
|
|---|---|
SAXParser() 受保护的构造函数以防止实例化。 |
|
公共方法(Public methods) |
|
|---|---|
abstract Parser |
getParser() 返回由此类的实现封装的SAX解析器。 |
abstract Object |
getProperty(String name) 返回 |
Schema |
getSchema() 获取对XML处理器正在使用的 |
abstract XMLReader |
getXMLReader() 返回由此类的实现封装的 |
abstract boolean |
isNamespaceAware() 指示此分析器是否配置为了解命名空间。 |
abstract boolean |
isValidating() 指示此分析器是否配置为验证XML文档。 |
boolean |
isXIncludeAware() 获取此解析器的XInclude处理模式。 |
void |
parse(InputSource is, DefaultHandler dh) 使用指定的 |
void |
parse(InputSource is, HandlerBase hb) 使用指定的 |
void |
parse(InputStream is, HandlerBase hb, String systemId) 使用指定的 |
void |
parse(String uri, HandlerBase hb) 使用指定的 |
void |
parse(File f, HandlerBase hb) 使用指定的 |
void |
parse(String uri, DefaultHandler dh) 使用指定的 |
void |
parse(InputStream is, HandlerBase hb) 使用指定的 |
void |
parse(File f, DefaultHandler dh) 使用指定的 |
void |
parse(InputStream is, DefaultHandler dh) 使用指定的 |
void |
parse(InputStream is, DefaultHandler dh, String systemId) 使用指定的 |
void |
reset() 将此 |
abstract void |
setProperty(String name, Object value) 设置底层实现 |
继承方法(Inherited methods) |
|
|---|---|
java.lang.Object
|
|
Parser getParser ()
返回由此类的实现封装的SAX解析器。
| 返回(Returns) | |
|---|---|
Parser |
The SAX parser that is encapsulated by the implementation of this class. |
| 抛出异常(Throws) | |
|---|---|
SAXException |
If any SAX errors occur during processing. |
Object getProperty (String name)
返回底层实现 XMLReader请求的特定属性。
| 参数(Parameters) | |
|---|---|
name |
String: The name of the property to be retrieved. |
| 返回(Returns) | |
|---|---|
Object |
Value of the requested property. |
| 抛出异常(Throws) | |
|---|---|
SAXNotRecognizedException |
When the underlying XMLReader does not recognize the property name. |
SAXNotSupportedException |
When the underlying XMLReader recognizes the property name but doesn't support the property. |
也可以看看:
Schema getSchema ()
获取XML处理器正在使用的 Schema的引用。
如果没有使用模式,则返回 null 。
| 返回(Returns) | |
|---|---|
Schema |
Schema being used or null if none in use |
| 抛出异常(Throws) | |
|---|---|
UnsupportedOperationException |
For backward compatibility, when implementations for earlier versions of JAXP is used, this exception will be thrown. |
XMLReader getXMLReader ()
返回由此类的实现封装的 XMLReader 。
| 返回(Returns) | |
|---|---|
XMLReader |
The XMLReader that is encapsulated by the implementation of this class. |
| 抛出异常(Throws) | |
|---|---|
SAXException |
If any SAX errors occur during processing. |
boolean isNamespaceAware ()
指示此分析器是否配置为了解命名空间。
| 返回(Returns) | |
|---|---|
boolean |
true if this parser is configured to understand namespaces; false otherwise. |
boolean isValidating ()
指示此分析器是否配置为验证XML文档。
| 返回(Returns) | |
|---|---|
boolean |
true if this parser is configured to validate XML documents; false otherwise. |
boolean isXIncludeAware ()
获取此解析器的XInclude处理模式。
| 返回(Returns) | |
|---|---|
boolean |
the return value of the isXIncludeAware() when this parser was created from factory. |
| 抛出异常(Throws) | |
|---|---|
UnsupportedOperationException |
For backward compatibility, when implementations for earlier versions of JAXP is used, this exception will be thrown. |
也可以看看:
void parse (InputSource is, DefaultHandler dh)
使用指定的 DefaultHandler将给定 InputSource的内容解析为XML。
| 参数(Parameters) | |
|---|---|
is |
InputSource: The InputSource containing the content to be parsed. |
dh |
DefaultHandler: The SAX DefaultHandler to use. |
| 抛出异常(Throws) | |
|---|---|
IllegalArgumentException |
If the InputSource object is null. |
IOException |
If any IO errors occur. |
SAXException |
If any SAX errors occur during processing. |
也可以看看:
void parse (InputSource is, HandlerBase hb)
使用指定的HandlerBase将给定InputSource的内容解析为XML。 建议使用此方法的DefaultHandler版本,因为HandlerBase类已在SAX 2.0中弃用
| 参数(Parameters) | |
|---|---|
is |
InputSource: The InputSource containing the content to be parsed. |
hb |
HandlerBase: The SAX HandlerBase to use. |
| 抛出异常(Throws) | |
|---|---|
IllegalArgumentException |
If the InputSource object is null. |
IOException |
If any IO errors occur. |
SAXException |
If any SAX errors occur during processing. |
也可以看看:
void parse (InputStream is, HandlerBase hb, String systemId)
使用指定的HandlerBase将给定的InputStream实例的内容解析为XML。 建议使用此方法的DefaultHandler版本,因为HandlerBase类已在SAX 2.0中弃用 。
| 参数(Parameters) | |
|---|---|
is |
InputStream: InputStream containing the content to be parsed. |
hb |
HandlerBase: The SAX HandlerBase to use. |
systemId |
String: The systemId which is needed for resolving relative URIs. |
| 抛出异常(Throws) | |
|---|---|
IllegalArgumentException |
If the given InputStream is null. |
IOException |
If any IO error occurs interacting with the InputStream. |
SAXException |
If any SAX errors occur during processing. |
void parse (String uri, HandlerBase hb)
使用指定的HandlerBase解析由统一资源标识符(URI)描述为XML的HandlerBase 。 建议使用此方法的DefaultHandler版本,因为HandlerBase类已在SAX 2.0中弃用
| 参数(Parameters) | |
|---|---|
uri |
String: The location of the content to be parsed. |
hb |
HandlerBase: The SAX HandlerBase to use. |
| 抛出异常(Throws) | |
|---|---|
IllegalArgumentException |
If the uri is null. |
IOException |
If any IO errors occur. |
SAXException |
If any SAX errors occur during processing. |
也可以看看:
void parse (File f, HandlerBase hb)
使用指定的HandlerBase解析指定为XML的文件的内容。 建议使用此方法的DefaultHandler版本,因为HandlerBase类已在SAX 2.0中弃用
| 参数(Parameters) | |
|---|---|
f |
File: The file containing the XML to parse |
hb |
HandlerBase: The SAX HandlerBase to use. |
| 抛出异常(Throws) | |
|---|---|
IllegalArgumentException |
If the File object is null. |
IOException |
If any IO errors occur. |
SAXException |
If any SAX errors occur during processing. |
也可以看看:
void parse (String uri, DefaultHandler dh)
使用指定的 DefaultHandler解析由统一资源标识符(URI)描述为XML的 DefaultHandler 。
| 参数(Parameters) | |
|---|---|
uri |
String: The location of the content to be parsed. |
dh |
DefaultHandler: The SAX DefaultHandler to use. |
| 抛出异常(Throws) | |
|---|---|
IllegalArgumentException |
If the uri is null. |
IOException |
If any IO errors occur. |
SAXException |
If any SAX errors occur during processing. |
也可以看看:
void parse (InputStream is, HandlerBase hb)
使用指定的HandlerBase将给定的InputStream实例的内容解析为XML。 建议使用此方法的DefaultHandler版本,因为HandlerBase类已在SAX 2.0中弃用 。
| 参数(Parameters) | |
|---|---|
is |
InputStream: InputStream containing the content to be parsed. |
hb |
HandlerBase: The SAX HandlerBase to use. |
| 抛出异常(Throws) | |
|---|---|
IllegalArgumentException |
If the given InputStream is null. |
SAXException |
If parse produces a SAX error. |
IOException |
If an IO error occurs interacting with the InputStream. |
也可以看看:
void parse (File f, DefaultHandler dh)
使用指定的 DefaultHandler解析指定为XML的文件的内容。
| 参数(Parameters) | |
|---|---|
f |
File: The file containing the XML to parse |
dh |
DefaultHandler: The SAX DefaultHandler to use. |
| 抛出异常(Throws) | |
|---|---|
IllegalArgumentException |
If the File object is null. |
IOException |
If any IO errors occur. |
SAXException |
If any SAX errors occur during processing. |
也可以看看:
void parse (InputStream is, DefaultHandler dh)
使用指定的 DefaultHandler将给定的 InputStream实例的内容解析为XML。
| 参数(Parameters) | |
|---|---|
is |
InputStream: InputStream containing the content to be parsed. |
dh |
DefaultHandler: The SAX DefaultHandler to use. |
| 抛出异常(Throws) | |
|---|---|
IllegalArgumentException |
If the given InputStream is null. |
IOException |
If any IO errors occur. |
SAXException |
If any SAX errors occur during processing. |
也可以看看:
void parse (InputStream is, DefaultHandler dh, String systemId)
使用指定的 DefaultHandler将给定的 InputStream实例的内容解析为XML。
| 参数(Parameters) | |
|---|---|
is |
InputStream: InputStream containing the content to be parsed. |
dh |
DefaultHandler: The SAX DefaultHandler to use. |
systemId |
String: The systemId which is needed for resolving relative URIs. |
| 抛出异常(Throws) | |
|---|---|
IllegalArgumentException |
If the given InputStream is null. |
IOException |
If any IO errors occur. |
SAXException |
If any SAX errors occur during processing. |
void reset ()
将此 SAXParser重置为其原始配置。
SAXParser重置为与使用newSAXParser()创建时相同的状态。 reset()旨在允许重复使用现有的SAXParser从而节省与创建新的SAXParser相关的资源。
重置SAXParser不保证具有相同的Schema Object ,例如equals(Object) 。 它保证有一个功能相同的Schema 。
void setProperty (String name, Object value)
设置底层实现XMLReader的特定属性。 核心功能和属性列表可在http://sax.sourceforge.net/?selected=get-set找到。
| 参数(Parameters) | |
|---|---|
name |
String: The name of the property to be set. |
value |
Object: The value of the property to be set. |
| 抛出异常(Throws) | |
|---|---|
SAXNotRecognizedException |
When the underlying XMLReader does not recognize the property name. |
SAXNotSupportedException |
When the underlying XMLReader recognizes the property name but doesn't support the property. |
也可以看看: