Most visited

Recently visited

Added in API level 1

XMLReaderFactory

public final class XMLReaderFactory
extends Object

java.lang.Object
   ↳ org.xml.sax.helpers.XMLReaderFactory


用于创建XML阅读器的工厂。

This module, both source code and documentation, is in the Public Domain, and comes with NO WARRANTY. See http://www.saxproject.org for further information.

该类包含用于从显式类名创建XML读取器或基于运行时默认值的静态方法:

 try {
   XMLReader myReader = XMLReaderFactory.createXMLReader();
 } catch (SAXException e) {
   System.err.println(e.getMessage());
 }
 

与分析器捆绑在一起的分发注意事项:您应该修改无参数createXMLReader的实现以处理未设置外部配置机制的情况。 当一个类在路径中时,该方法应该尽最大努力返回解析器,即使没有任何类名绑定到org.xml.sax.driver以便这些配置机制可以看到它。

Summary

Public methods

static XMLReader createXMLReader()

尝试从系统默认值创建XMLReader。

static XMLReader createXMLReader(String className)

尝试从类名创建XML读取器。

Inherited methods

From class java.lang.Object

Public methods

createXMLReader

Added in API level 1
XMLReader createXMLReader ()

尝试从系统默认值创建XMLReader。 在可以支持它的环境中,XMLReader类的名称是通过按顺序尝试每个这些选项并使用第一个成功的名称来确定的:

  • If the system property org.xml.sax.driver has a value, that is used as an XMLReader class name.
  • The JAR "Services API" is used to look for a class name in the META-INF/services/org.xml.sax.driver file in jarfiles available to the runtime.
  • SAX parser distributions are strongly encouraged to provide a default XMLReader class name that will take effect only when previous options (on this list) are not successful.
  • Finally, if makeParser() can return a system default SAX1 parser, that parser is wrapped in a ParserAdapter. (This is a migration aid for SAX1 environments, where the org.xml.sax.parser system property will often be usable.)

在小型嵌入式系统等无法支持这种灵活性的环境中,可以使用其他确定默认值的机制。

请注意,许多Java环境允许在命令行上初始化系统属性。 这意味着在大多数情况下 ,为该属性设置好的值可以确保对此方法的调用会成功,除非安全策略干预。 这也将使应用程序可移植性最大化到较老的SAX环境,而这种方法的稳健性较差。

Returns
XMLReader A new XMLReader.
Throws
SAXException If no default XMLReader class can be identified and instantiated.

也可以看看:

createXMLReader

Added in API level 1
XMLReader createXMLReader (String className)

尝试从类名创建XML读取器。

给定一个类名称,该方法尝试加载并实例化类作为XML阅读器。

Parameters
className String: the name of the class that should be instantiated.

请注意,此方法在调用方(可能是小应用程序)不允许动态加载类的环境中不可用。

Returns
XMLReader A new XML reader.
Throws
SAXException If the class cannot be loaded, instantiated, and cast to XMLReader.

也可以看看:

Hooray!