【问题标题】:XSD Error: attribute 'substitutiongroup' cannot appear in element 'element'XSD 错误:属性 'substitutiongroup' 不能出现在元素 'element' 中
【发布时间】:2014-08-22 20:45:33
【问题描述】:

得到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>

我做错了什么?

【问题讨论】:

  • 只有当元素是 schema 标记的子元素时,才能使用属性 substitutionGroup。此外,您尝试在元素内定义属性的方式不正确(您可能想使用一些 complexType)。

标签: xsd


【解决方案1】:

你应该使用这个 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>

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

【讨论】:

  • 那个 xsd 无效。正如我在评论中所说,只有当具有该属性的元素是模式标记的直接子元素时,才能使用属性替代组。此外,属性 nillablemaxOccursminOccurs 永远不能成为 complexType 元素的一部分。
猜你喜欢
  • 2017-03-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-08-21
  • 2018-10-23
  • 1970-01-01
  • 2012-09-09
相关资源
最近更新 更多