XSD错误:属性'替换组'不能出现在元素'元素中

时间:2014-08-22 20:45:33

标签: xsd

此问题导致attribute 'substitutiongroup' cannot appear in element 'element'错误:

  <xs:complexType name="Attributes" abstract="false">
    <xs:sequence>
      <xs:element name="Attribute" nillable="true" minOccurs="0" maxOccurs="unbounded">
        <xs:attribute name="type" type="xs:string" />
      </xs:element>
      <xs:element name="DutyRating" substitutionGroup="Attribute"/>
      <xs:element name="Width" substitutionGroup="Attribute"/>
      <xs:element name="SampleSet" substitutionGroup="Attribute"/>
    </xs:sequence>
  </xs:complexType>

我做错了什么?

1 个答案:

答案 0 :(得分:0)

你应该使用这个xsd ......

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema" 
    targetNamespace="yourNamespace" xmlns:prefix="yourNamespace">

   <xs:complexType name="Attributes" abstract="false">
    <xs:sequence>
      <xs:element name="Attribute" substitutionGroup="prefix:Attribute"/>
      <xs:element name="DutyRating" substitutionGroup="prefix:Attribute"/>
      <xs:element name="Width" substitutionGroup="prefix:Attribute"/>
      <xs:element name="SampleSet" substitutionGroup="prefix:Attribute"/>
    </xs:sequence>
  </xs:complexType>

  <xs:element name="Attribute" type="prefix:Attribute"/>
  <xs:complexType  name="Attribute" nillable="true" minOccurs="0" maxOccurs="unbounded">
    <xs:attribute name="type" type="xs:string" />
  </xs:complexType>

</xs:schema>

我希望我已经向你提供了有关你问题的所有答案。