Xerces2-j XMLInputSource以及SAX InputSource引用公共和系统标识符。Xerces2-J XMLInputSource也指基本系统标识符。
这些标识符代表什么?
编辑: Xerces-J,当给出文件位置作为SystemId时,将文件作为输入打开。如果输入是以字节流的形式提供的,而不是从其他源(如数据库)提供的,那么公共或系统id有什么用途吗?
发布于 2022-01-14 17:55:42
如果您查看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,它标识在哪里可以找到实体的文本。“公共标识符”(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。
在回答您的问题“公共或系统标识是否有任何目的”时,如果文档完全由单个实体组成(通常是这样的),则答案是否定的。但是,一旦多个实体发挥作用,您就需要标识符将它们连接在一起。
发布于 2022-01-14 17:47:55
如果输入是以字节流的形式提供的,而不是从其他源(如数据库)提供的,那么公共或系统id有什么用途吗?
否,因为如果输入是字节流,则不需要解析实体的位置。
这些标识符代表什么?
我认为这条线解释得很好:
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)https://stackoverflow.com/questions/70713901
复制相似问题