[英]When to use W3C's xmlns and xmlns:xsi namespaces?
I have a rather fundamental question about XML here.我在这里有一个关于 XML 的相当基本的问题。 When declaring an element's
xmlns
attribute, is it ever legal to use http://www.w3.org/2001/XMLSchema
?在声明元素的
xmlns
属性时,使用http://www.w3.org/2001/XMLSchema
是否合法? And when declaring the xmlns:xsi
attribute, is it legal to use http://www.w3.org/2001/XMLSchema-instance
as the value?并且在声明
xmlns:xsi
属性时,使用http://www.w3.org/2001/XMLSchema-instance
作为值是否合法?
I ask this because I have seen XML auto-generated by some XML editors which references these namespaces, and yet (at least on the XMLSchema-instance
page) W3C says that "This schema should never be used as such: the XML Schema Recommendation forbids the declaration of attributes in this namespace". I ask this because I have seen XML auto-generated by some XML editors which references these namespaces, and yet (at least on the
XMLSchema-instance
page) W3C says that "This schema should never be used as such: the XML Schema Recommendation forbids此命名空间中的属性声明”。
So I'm confused;所以我很困惑; is it always illegal to say something like:
说这样的话总是违法的:
<?xml version="1.0" encoding="UTF-8"?>
<myElement xmlns="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
[...]
</myElement>
... and if not, why does W3C seem to say that the namespace should never be used? ...如果不是,为什么 W3C 似乎说永远不应该使用命名空间? What would one use it for?
一个人会用它做什么? I've tried to read the XML 1.0 spec but it's extremely verbose and difficult to understand.
我尝试阅读 XML 1.0 规范,但它非常冗长且难以理解。
That namespace should not be used for anything else.该名称空间不应用于其他任何用途。 It must be used to reference the attributes declared within that namespace.
它必须用于引用在该命名空间中声明的属性。
You may not declare any elements or attributes within a namespace that belongs to someone else.您不得在属于其他人的命名空间中声明任何元素或属性。 This means you may not declare your
myElement
within the "XMLSchema" namespace.这意味着您不能在“XMLSchema”命名空间中声明您的
myElement
。
<?xml version="1.0" encoding="UTF-8"?>
<root xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<genericElement xsi:type="xs:string">string</genericElement>
</root>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.