1
我有一个简单类型的简单模式定义:XSD定义简单类型+限制+ anyAttribute
<xs:simpleType name="std_types-bit-type">
<xs:restriction base="xs:int">
<xs:minInclusive value="0"/>
<xs:maxInclusive value="1"/>
</xs:restriction>
</xs:simpleType>
其他地方有:
<xs:element name="comp" type="std_types-bit-type"/>
一个可以创建这样的XML元素:
<comp>1</comp>
我想允许文档创建者添加任意(对我来说,但对他们有意义)属性如:
<comp index="2">1</comp>
既然不能提前知道的所有可能的属性,xs:anyAttribute
适用于只是这种情况。事实上,为complexTypes定义这个很简单。问题在于,我无法找到模式元素的神奇组合,它们让xs:anyAttribute
与simpleType/simpleContent限制相关联。
我无法想象这是不可能的,但它迄今为止都在殴打我。
呀,我害怕这一点。一个简单的元素定义为两个。由于架构是工具生成的(而且我正在编写该工具),这意味着更复杂。 xs:anyAttribute也必须存在于扩展和限制(或xmllint树皮)中。 – 2014-10-07 15:31:47
我回滚了我的编辑,因为我误解了你的答案。我的一个解决方案涉及将xs:int(将xs:anyAttribute添加到complexType中),然后限制它。 xs:attribute在xs:complexType中的xs:simpleContent内的xs:restriction内是有效的。重读你的答案,这次我看到你先限制了基本类型,然后用xs:anyAttribute扩展它。这显然是一个更清洁的方法。对不起,错误... – 2014-10-07 19:29:50