Bil*_*ill 5 xml xsd restriction complextype
我正在尝试继承并限制一个元素,但我得到了以下错误(在eclipse验证中):
该类型的颗粒不是对碱的颗粒的有效限制.
"Description"元素不应该是"TypeDevice"元素的一部分.我无法理解为什么.这应该是可能的(根据本教程):
谁能帮我?
映入眼帘,
法案
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.com" xmlns="http://www.example.com" elementFormDefault="qualified" attributeFormDefault="unqualified">
<!-- Abstract Base Class -->
<xs:complexType name="AbstractDevice" abstract="true">
<xs:sequence>
<xs:element name="Name" type="xs:string" />
<xs:element name="Description" type="xs:string" />
</xs:sequence>
<xs:attribute name="id" type="xs:string" />
</xs:complexType>
<!-- Inheritance with restriction -->
<xs:complexType name="TypeDevice">
<xs:complexContent>
<xs:restriction base="AbstractDevice">
<xs:sequence>
<xs:element name="Name" type="xs:string" />
</xs:sequence>
<xs:attribute name="id" type="xs:string" use="required" />
</xs:restriction>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="TypeRoot">
<xs:sequence>
<xs:element name="Device" type="TypeDevice" />
</xs:sequence>
</xs:complexType>
<xs:element name="Configuration" type="TypeRoot" />
</xs:schema>
Run Code Online (Sandbox Code Playgroud)
TypeAbstractDevice有两个必需元素,而 typeTypeDevice只有一个。因此TypeDevice不是其基本类型的有效实例AbstractDevice。为了使其有效,您应该添加minOccurs="0"到Description元素或反转推导并使用扩展。
| 归档时间: |
|
| 查看次数: |
2753 次 |
| 最近记录: |