5
我想继承和制约因素,但我得到以下错误(在Eclipse中验证):XSD限制不起作用
类型的粒子不是有效限制基地的粒子 。
“Description”元素不应该是“TypeDevice”元素的一部分。我不明白为什么。这应该是可能的(根据此tutorial):
任何人都可以帮助我吗?
映入眼帘,
比尔
<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>
感谢您的回答。但我想,这正是对一个元素应用限制可以做到的。链接的教程完全是这样做的(限制派生条件“小册子”中的基本类型“Book”的元素“作者”限制。也许我在这里误解了某些东西。顺便说一句,在我的实现中不可能设置Description到基本元素中的“minOccurs = 0”。 – Bill 2013-02-19 07:05:54