Difference/similarities 介于 xs:anyType 和不受约束的 xs:element 之间

Difference/similarities between xs:anyType and unconstrained xs:element

无约束元素有什么区别,例如:

<?xml version="1.0" encoding="utf-8"?>
<xs:schema elementFormDefault="qualified" targetNamespace="http://tempuri.org/" xmlns:tns="http://tempuri.org/import" xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:element name="a"></xs:element>
</xs:schema>

和类型为 xs:anyType 的元素,例如:

<?xml version="1.0" encoding="utf-8"?>
<xs:schema elementFormDefault="qualified" targetNamespace="http://tempuri.org/" xmlns:tns="http://tempuri.org/import" xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:element name="b" type="xs:anyType"></xs:element>
</xs:schema>

?

两者都允许任何内容并且不施加限制。有什么不同吗?我已经阅读了相关规范,但这些规范并没有澄清我对它们之间差异的困惑(如果有的话)。

没有区别

xs:element/@type 的默认值为 ur-type,也称为 anyType

参见 3.3.2 XML Representation of Element Declaration Schema Components:

{type definition}: The type definition corresponding to the <simpleType> or <complexType> element information item in the [children], if either is present, otherwise the type definition ·resolved· to by the ·actual value· of the type [attribute], otherwise the {type definition} of the element declaration ·resolved· to by the ·actual value· of the substitutionGroup [attribute], if present, otherwise the ·ur-type definition·.

另见 2.2.1.1 Type Definition Hierarchy:

[Definition:] A distinguished complex type definition, the ur-type definition, whose name is anyType in the XML Schema namespace, is present in each ·XML Schema·, serving as the root of the type definition hierarchy for that schema.

相关: