为什么“ref”在这种情况下不起作用:
<xs:complexType name="Team">
<xs:sequence>
<xs:element name="Name" type="xs:string"/>
<xs:element name="Size">
<xs:simpleType>
<xs:restriction base="xs:integer">
<xs:totalDigits value="1"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element ref="Size"/>
</xs:sequence>
</xs:complexType>
元素Size具有局部作用域,难道不能在局部复用吗?
编辑:上面的情况可能没有多大意义。考虑下面的情况,是否没有办法重用现有的“Size”定义:
<xs:complexType name="Team">
<xs:sequence>
<xs:element name="Name" type="xs:string"/>
<xs:element name="Size">
<xs:simpleType>
<xs:restriction base="xs:integer">
<xs:totalDigits value="1"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="teamLeads">
<xs:complexType>
<xs:sequence>
<xs:element ref="Size"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
最佳答案
您只能引用顶级元素。
{term} The (top-level) element declaration ·resolved· to by the ·actual value· of the
ref
[attribute].
http://www.w3.org/TR/2004/REC-xmlschema-1-20041028/structures.html#declare-element (请参阅框中的最后一部分)
关于xml - 如何在同一父标签下重用本地定义的元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14117470/