xsd:anySimpleType对xsd:anyType有什么限制,在什么地方枚举?

What are the restrictions of xsd:anySimpleType on xsd:anyType, and where are they enumerated?

anyType 类型的元素允许具有任何属性和任何值-space 内容,包括子元素。 anySimpleType的限制在哪里?我对仅允许指定(由给定 XSD 文档)属性的限制特别感兴趣。

假设 libxml2 的模式验证符合规范,下面显示了 anySimpleType 的至少一个限制:

foo.xsd:

<?xml version="1.0" encoding="utf-8"?>

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="Foo">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="Bar" type="xs:anyType" />
        <xs:element name="Baz" type="xs:anySimpleType" />
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

foo.xml:

<?xml version="1.0" encoding="utf-8"?>

<Foo>
  <Bar abc="xyz" />
  <Baz abc="xyz" />
</Foo>

验证:

$ xmllint --noout foo.xml --schema foo.xsd 
foo.xml:5: element Baz: Schemas validity error : Element 'Baz', attribute 'abc': The attribute 'abc' is not allowed.
foo.xml fails to validate

anySimpleType 是抽象基简单类型。完全不受限制。

http://www.datypic.com/sc/xsd/t-xsd_anySimpleType.html

如果你想指定只允许一个属性列表,那就是"complex types"的工作,比如simpleType。 (给这些起个好名字吧?=/)

http://www.datypic.com/sc/xsd/t-xsd_simpleType.html

[重新编辑你的例子]:

啊,好的,我明白你在问什么了

在 XSD "simple" 类型中,不能有属性,而不是通过限制。 (一些解析器允许一些默认属性,例如 NS http://www.w3.org/2001/XMLSchema-instance 中的 {'type'、'nil'、'schemaLocation'、'noNamespaceSchemaLocation'};这些对于扩展此功能很有用基本类型。)它们旨在是原子的,文字的,等等 - 任何可以是 XML.

中属性的 /value/ 的东西

anySimpleType 顾名思义——完全不受限制的简单类型。它不能采用属性 'abc',因为简单类型不能有属性——它们是属性值。如果你想让一个元素接受一个属性列表,正如我上面所说,那是 "complex" 类型的工作,而不是 "simple" 类型。

这包含在规范中:https://www.w3.org/TR/xmlschema11-1/#Type_Derivation

一个xsd:anyType can be complex or simple (xsd:anySimpleType)。只有复杂类型可以有属性。

xsd:anyTypexsd:anySimpleType(以及所有复杂类型)之间的关系可以在W3C的XSD建议图中清楚地看到:3 Built-in datatypes