java SAX解析器实际上是从internet检索DTD吗?

时间:2021-12-02 01:09:00

With an XML file that declares a DOCTYPE, take the struts.xml file for instance:

使用声明DOCTYPE的XML文件,使用struts。xml文件例如:

Does the Java SAX processing actually go get the dtd from the provided URL?

Java SAX处理实际上是从提供的URL获取dtd吗?

3 个解决方案

#1


4  

Many (most) implementations will, even though technically, if I remember correctly, the location is meant to be interpreted as a URI, not URL.

许多(大多数)实现,即使在技术上,如果我没记错的话,也会被解释为URI,而不是URL。

If you want to be sure to resolve it locally, take a look at the EntityResolver interface.

如果您希望确保在本地解决它,请查看EntityResolver接口。

#2


3  

Based on the Xerces documentation, the parser may try to download the file from the internet when validation is turned on. But I really think this can change from parser to parser, because the library may decide to use a local cache, a proxy server or whatever.

基于Xerces文档,当打开验证时,解析器可能尝试从internet下载文件。但是我真的认为这可以从解析器改变到解析器,因为库可能决定使用本地缓存、代理服务器或其他东西。

#3


0  

You can modify the struts.xml to load the DTD file from the struts2 core jar from the classpath rather than loading it from internet

您可以修改struts。从类路径加载struts2核心jar中的DTD文件,而不是从internet加载它

FROM

<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts 
Configuration//EN" 
"http://struts.apache.org/dtds/struts-2.0.dtd"> 

CHANGE TO

改变

<!DOCTYPE struts SYSTEM "struts-2.0.dtd">

now the sax parser loaded the struts-2.0.dtd file from the /src folder where i placed.

现在,sax解析器装载了struts-2.0。我放置的/src文件夹中的dtd文件。

Also this is my modified hibernate configuration file which worked a little differently. It loaded the dtd file directly from the JAR, did not have to physically place it in the src folder

这是我修改过的hibernate配置文件,它的工作方式有点不同。它直接从JAR加载dtd文件,不需要物理地将其放在src文件夹中

<!DOCTYPE hibernate-configuration SYSTEM "classpath://org/hibernate/hibernate-configuration-3.0.dtd">

#1


4  

Many (most) implementations will, even though technically, if I remember correctly, the location is meant to be interpreted as a URI, not URL.

许多(大多数)实现,即使在技术上,如果我没记错的话,也会被解释为URI,而不是URL。

If you want to be sure to resolve it locally, take a look at the EntityResolver interface.

如果您希望确保在本地解决它,请查看EntityResolver接口。

#2


3  

Based on the Xerces documentation, the parser may try to download the file from the internet when validation is turned on. But I really think this can change from parser to parser, because the library may decide to use a local cache, a proxy server or whatever.

基于Xerces文档,当打开验证时,解析器可能尝试从internet下载文件。但是我真的认为这可以从解析器改变到解析器,因为库可能决定使用本地缓存、代理服务器或其他东西。

#3


0  

You can modify the struts.xml to load the DTD file from the struts2 core jar from the classpath rather than loading it from internet

您可以修改struts。从类路径加载struts2核心jar中的DTD文件,而不是从internet加载它

FROM

<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts 
Configuration//EN" 
"http://struts.apache.org/dtds/struts-2.0.dtd"> 

CHANGE TO

改变

<!DOCTYPE struts SYSTEM "struts-2.0.dtd">

now the sax parser loaded the struts-2.0.dtd file from the /src folder where i placed.

现在,sax解析器装载了struts-2.0。我放置的/src文件夹中的dtd文件。

Also this is my modified hibernate configuration file which worked a little differently. It loaded the dtd file directly from the JAR, did not have to physically place it in the src folder

这是我修改过的hibernate配置文件,它的工作方式有点不同。它直接从JAR加载dtd文件,不需要物理地将其放在src文件夹中

<!DOCTYPE hibernate-configuration SYSTEM "classpath://org/hibernate/hibernate-configuration-3.0.dtd">