[英]Why xmlns:xsi, and not only xsi in XML documents?
I understand that, by convention, the default namespace is named xmlns
attribute in the root element of an XML document. 据我所知,按照惯例,默认命名空间在XML文档的根元素中被命名为
xmlns
属性。 Other namespaces are named other names. 其他名称空间被命名为其他名称。 Now, I wonder why is XML Scheme Instance namespace always named
xmlns:xsi
and not simply xsi
? 现在,我想知道为什么XML Scheme Instance命名空间总是命名为
xmlns:xsi
而不仅仅是xsi
? Would xsi
be the same as xmlns:xsi
? xsi
会与xmlns:xsi
相同吗? If yes, why yes? 如果是,为什么是? If no, why no?
如果不是,为什么不呢?
Elements and attribute names not coming from the default namespace are always preceded by name of the namespace. 不是来自默认命名空间的元素和属性名称始终以命名空间的名称开头。 Having
xmlns:xsi
tells me that xsi
is an attribute defined in namespace xmlns
, which is conflicting, since the attribute names from the default namespace shouldn't be preceded by the namespace. 有了
xmlns:xsi
告诉我xsi
是在命名空间xmlns
定义的属性,它是冲突的,因为默认命名空间中的属性名称不应该在命名空间之前。
The default namespace is not named xmlns
. 默认命名空间未命名为
xmlns
。
xmlns
is the way to declare a namespace prefix (ie short name, handle). xmlns
是声明名称空间前缀 (即短名称,句柄)的方式。 The syntax is xmlns[:prefix]="namepace-uri"
. 语法是
xmlns[:prefix]="namepace-uri"
。
There can be exactly one namespace declaration per XML element where you are allowed to leave off the prefix ( xmlns="namespace-uri"
), and if it is declared that way it is called "default namespace". 每个XML元素可以只有一个名称空间声明,您可以在其中
xmlns="namespace-uri"
前缀( xmlns="namespace-uri"
),如果以这种方式声明它,则称为“默认名称空间”。
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
declares that the URI http://www.w3.org/2001/XMLSchema-instance
shall be known as xsi
inside this element. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
声明URI http://www.w3.org/2001/XMLSchema-instance
在此元素中应被称为xsi
。
You are free to choose any prefix you like, you can declare xmlns:bob="http://www.w3.org/2001/XMLSchema-instance"
and that would mean that the URI http://www.w3.org/2001/XMLSchema-instance
shall be known as bob
inside this element. 您可以自由选择任何您喜欢的前缀,您可以声明
xmlns:bob="http://www.w3.org/2001/XMLSchema-instance"
,这意味着URI http://www.w3.org/2001/XMLSchema-instance
在这个元素中应该被称为bob
。
By convention, many widely-used XML namespace URIs get the same prefix everywhere, but that's not a technical requirement. 按照惯例,许多广泛使用的XML命名空间URI在任何地方都获得相同的前缀,但这不是技术要求。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.