XML - 试图掌握名称空间 URI 的概念

XML - Trying to grasp the concept of namespace URI

如果我的 XSL 有以下标题,我不会收到错误:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"

但是如果我更改 xsl 命名空间 URI...:[=​​20=]

<xsl:stylesheet version="1.0" xmlns:xsl="https://www.w3schools.com/xml/xml_namespaces.asp"

...我收到一个错误:

javax.xml.transform.TransformerConfigurationException 

我想我不理解名称空间 URI 的概念,因为我认为它可以是任何 URL(更不用说 URN),只要它在 XML/XSL 中是唯一的即可文档。明显不是。我试图改变 URI 来测试这个理论。


https://www.w3schools.com/xml/xml_namespaces.asp,我们可以读到以下语句:

The namespace URI is not used by the parser to look up information.

The purpose of using an URI is to give the namespace a unique name.

However, companies often use the namespace as a pointer to a web page containing namespace information.

第一种说法的意思是我们不关心URI指向的网页是什么,那么为什么我不能设置它指向我想要的任何页面,甚至是不存在的页面呢?为什么它必须特别是 http://www.w3.org/1999/XSL/Transform ?

此外,在上面link后面我们可以读到:

A Uniform Resource Identifier (URI) is a string of characters which identifies an Internet Resource.

因此,正因为如此并且因为 "The purpose of using an URI is to give the namespace a unique name",这是否意味着 名称空间 URI 必须是 URL(再次强调,更不用说我绝对无法理解的 URN),这意味着我不能像这样设置命名空间:

xlmns:foo="A_random_but_unique_string"

我会以来自同一 link 的这句话结束:

The namespace "http://www.w3.org/1999/XSL/Transform" identifies XSLT elements inside an HTML document

所以现在就是说解析器肯定要使用命名空间URL来查找信息(命名空间的元素),不是吗?

它与解析 URL(和下载架构)无关。尽管 XML 在两个示例中看起来相同:"xsl:stylesheet",您的输入被读取为 stylesheet 元素(由命名空间 https://www.w3schools.com/xml/xml_namespaces.asp 标识)。

Java 程序需要一个 stylesheet 元素(由命名空间 http://www.w3.org/1999/XSL/Transform 标识),但是由于找不到它,因此抛出异常。