Public标识符、系统标识符和基本系统标识符在XML中指的是什么?

What do Public Identifier, System Identifier, and Base system identifier refer to in XML?

Xerces2-j XMLInputSource, and also SAX InputSource,参考public和系统标识符。 Xerces2-J XMLInputSource 也指基本系统标识符。

这些标识符代表什么?

编辑:Xerces-J,当给文件位置作为 SystemId 时,将打开文件作为输入。如果输入是作为字节流而不是来自其他来源(例如数据库)提供的,那么 public 或系统 ID 是否有任何用途?

If the input is provided as a byte stream instead from some other source such as a database, is there any purpose to the public or system id?

否,因为如果输入是字节流,则无需解析实体的位置。

What do these identifiers represent?

我认为这个帖子解释得很好:

SYSTEM declaration can be used to specify a file on the local file
system like:

<!DOCTYPE RootElement SYSTEM "C:\validate.dtd">

The problem with this approach is that if the file is made public the
path specified on the local file system will not have any meaning any
more. Even if the path specified in the SYSTEM declaration *is* a URL:

<!DOCTYPE RootElement SYSTEM "http://www.mihaiu.name/validate.dtd">

the parser might be unable to retrieve the DTD file if the system is
not connected to the Internet.

The PUBLIC declaration constitutes a partial solution to this problem.
The string contained in a PUBLIC declaration is not an URL but an URN
(Uniform Resource Name). A URN does not pinpoint the precise location
of the resource, but only clearly specify its name. The *parser* of the
document must be smart enough to be able to generate a URL from a URN
using some internal logic.

Example of a PUBLIC declaration:

<!DOCTYPE RootElement PUBLIC "mihaiu/validate.dtd"
SYSTEM "http://www.mihaiu.name/validate.dtd">

In this case, a custom parser that already has a catalogue of DTDs
published by mihaiu can generate a URL from the PUBLIC declaration. The
generated URL can look like

c:\DTDs\validate.dtd

There is no standard way to convert a URN to a URL, so, if this
conversion fails because the parser does not contain the internal logic
to perform such a conversion (or for whatever other reason) the parser
will attempt to use the SYSTEM declaration which in this case resolves
to

http://www.mihaiu.name/validate.dtd

Important observation:
Since there is no standard way to generate a URL from a URN the PUBLIC
declarations can only be useful for customized parsers !!! (e.g. they
are not useful for general purpose parsers like Xerces)

如果您查看 XML 语法,您会看到,例如外部实体引用使用语法:

ExternalID ::= 'SYSTEM' S SystemLiteral
  | 'PUBLIC' S PubidLiteral S SystemLiteral

下面是使用此语法的示例:

<!ENTITY open-hatch
         PUBLIC "-//Textuality//TEXT Standard open-hatch boilerplate//EN"
         "http://www.textuality.com/boilerplate/OpenHatch.xml">

对 DTD 的引用以相同的方式工作(实际上,外部 DTD 从技术上讲是一种实体)。

“系统标识符”是一个 URI,用于标识可以在何处找到实体的文本。 “public 标识符”(SGML 的后遗症)更像是资源的名称;如果您有某种索引或目录告诉您在哪里查找,它只会帮助您找到资源。

系统标识符通常作为相对 URI 引用(例如“books.dtd”)给出,需要相对于基本 URI 进行解析。基本 URI 通常是找到包含资源(或实体)的位置。例如,如果 XML 文档位于 http://my.com/lib/books.xml,则其基本 URI 为 http://my.com/lib/,然后相对 URI books.dtd 扩展为 http://my.com/lib/books.dtd.

在回答您的问题“public 或系统 ID 是否有任何用途”时,如果文档完全由单个实体组成(通常是这种情况),答案是否定的。但是一旦多个实体开始发挥作用,您就需要标识符将它们 link 放在一起。