java - 为什么我们要在 Hibernate 配置或映射文件中写入 <!DOCTYPE> 标记

标签 java xml hibernate xsd dtd

为了验证 xml,我们需要 dtd 或 xsd。如果我们想根据 dtd 验证 xml,那么我们需要编写这个。

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.org/dtd/hibernate-configuration-3.0.dtd">

当我们的 dtd 存在于文件系统中时,使用 SYSTEM;如果我们的 dtd 存在于某个网络中,则使用 PUBLIC。在这种情况下,如果我们正在写这个

"http://hibernate.org/dtd/hibernate-configuration-3.0.dtd"
意味着我们的 dtd 存在于具有此地址的网络中,并且我们的 hibernate-configuration xml 文件将根据此 dtd 进行验证。

但是为什么要写这个??????

"-//Hibernate/Hibernate Configuration DTD 3.0//EN"

所以请回答我的问题。

最佳答案

DOCTYPE 中的值 -//Hibernate/Hibernate Configuration DTD 3.0//ENFormal Public Identifier 。它唯一标识PUBLIC external entity ,并且可用于解析 URI 引用。

In addition to a system identifier, an external identifier may include a public identifier.

An XML processor attempting to retrieve the entity's content may use any combination of the public and system identifiers as well as additional information outside the scope of this specification to try to generate an alternative URI reference. If the processor is unable to do so, it must use the URI reference specified in the system literal. Before a match is attempted, all strings of white space in the public identifier must be normalized to single space characters (#x20), and leading and trailing white space must be removed.

此外,还有一个很好的引用资料解释了 FPI 的组成部分:https://www.quackit.com/xml/tutorial/dtd_fpi.cfm

Here's a real life example of an FPI. In this case, the DTD was created by the W3C for XHTML:

-//W3C//DTD XHTML 1.0 Transitional//EN

An FPI is made up of 4 fields, each separated by double forward slashes (//):

  1. - Indicates whether the DTD is connected to a formal standard or not. If the DTD hasn't been approved (for example, you've defined the DTD yourself), use a hypen (-). If the DTD has been approved by a nonstandards body, use a plus sign "+". If the DTD has been approved by a formal standards body this field should be a reference to the standard itself.

  2. W3C Holds the name of the group (or person) responsible for the DTD. The above example is maintained by the W3C, so "W3C" appears in the second field.

  3. DTD XHTML 1.0 Transitional Indicates the type of document that is being described. This usually contains some form of unique identifier (such as a version number).

  4. EN Specifies the language that the DTD uses. This is achieved by using the two letter identifier for the language (i.e. for english, use "EN").

关于java - 为什么我们要在 Hibernate 配置或映射文件中写入 &lt;!DOCTYPE> 标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50202033/

相关文章:

java - Android 中的文件/数据库在线同步

xml - libxml2 是否支持 XSD 1.1

c# - 将 & 添加到 XmlElement

java - 如何解决ObjectNotFoundException?

java - 具有投影的 Hibernate 条件不执行 @OneToMany 映射查询

java - 通过 hibernate 获取不同的值

java - 在 2 个 Bean 之间传递数据 JSF

java - 将对象映射到数据库的正确方法是什么

java - 如何在属性类型为varchar(254)的数据库中对长字符串进行编码?

php - 如何使用 php DOM 获取 &lt;![CDATA[values]] > 中的值?