Java 8 中的默认 SAX 解析器

问题描述 投票:0回答:1

我正在努力理清 SAX/DOM 与 Java 集成的顺序。我发现网上的信息很混乱。如果有人能回答一些(可能是刀子)简单的问题,我将不胜感激。 这是我的环境:

  • 日食氧气。
  • Java 8。
  • 没有任何依赖项的 Maven 项目(是一个简单的控制台测试项目)。

我的问题

  • Java 8 打包了哪些解析器 (SAX/DOM)(如果有)?我在互联网上找不到信息。
  • 从我的环境中删除 CLASSPATH 后,确保未设置
    org.xml.sax.driver
    系统属性,
    XMLReaderFactory.createXMLReader()
    方法仍然返回一个对象
    com.sun.org.apache.xerces.internal.parsers.SAXParser
    。它从哪里来?
java-8 sax
1个回答
0
投票

https://docs.oracle.com/javase/8/docs/api/javax/xml/parsers/SAXParserFactory.html

https://docs.oracle.com/javase/8/docs/api/javax/xml/parsers/SAXParserFactory.html#newInstance--

获取 SAXParserFactory 的新实例。此静态方法创建一个新的工厂实例此方法使用以下有序查找过程来确定要加载的 SAXParserFactory 实现类:

Use the javax.xml.parsers.SAXParserFactory system property.
Use the properties file "lib/jaxp.properties" in the JRE directory. This configuration file is in standard java.util.Properties format and contains the fully qualified name of the implementation class with the key being the system property defined above. The jaxp.properties file is read only once by the JAXP implementation and it's values are then cached for future use. If the file does not exist when the first attempt is made to read from it, no further attempts are made to check for its existence. It is not possible to change the value of any property in jaxp.properties after it has been read for the first time.
Use the service-provider loading facilities, defined by the ServiceLoader class, to attempt to locate and load an implementation of the service using the default loading mechanism: the service-provider loading facility will use the current thread's context class loader to attempt to load the service. If the context class loader is null, the system class loader will be used.
Otherwise the system-default implementation is returned.

一旦应用程序获得了对 SAXParserFactory 的引用,它就可以使用该工厂来配置和获取解析器实例。

© www.soinside.com 2019 - 2024. All rights reserved.