9

要素「テスト」が必要であることを検証したい

  • コンテンツを制限する (たとえば、パターン制限を使用する)、および
  • 特定の属性 (「id」、「class」、「name」など) を含みます。

私が書いているXSDは次のようになります。

<xsd:element name="Test" minOccurs="0" maxOccurs="unbounded">
  <xsd:complexType mixed="true">
    <xsd:simpleContent>
      <xsd:restriction>
        <xsd:pattern value="xyz"/>
      </xsd:restriction>
    </xsd:simpleContent>
    <xsd:attribute name="id" type="xsd:string"></xsd:attribute>
    <xsd:attribute name="class" type="xsd:string"></xsd:attribute>
    <xsd:attribute name="name" type="xsd:string"></xsd:attribute>
  </xsd:complexType>
</xsd:element>

ただし、これを Visual Studio でコーディングすると、「xsd:attribute」要素で次のエラーが発生します。

「属性」とコンテンツ モデルは相互に排他的です

同じ要素のコンテンツ制限と属性の両方を検証する方法はありますか?

4

1 に答える 1

14

制限を分離して名前を付け、それを拡張機能の基本型として参照する必要があります。このような:

  <xsd:simpleType name="RestrictedString">
    <xsd:restriction base="xsd:string">
      <xsd:pattern value="xyz" />
    </xsd:restriction>
  </xsd:simpleType>
  <xsd:element name="Test">
    <xsd:complexType>
      <xsd:simpleContent>
        <xsd:extension base="RestrictedString">
          <xsd:attribute name="id" type="xsd:string" />
          <xsd:attribute name="class" type="xsd:string" />
          <xsd:attribute name="name" type="xsd:string" />
        </xsd:extension>
      </xsd:simpleContent>
    </xsd:complexType>
  </xsd:element>
于 2011-09-21T02:33:43.673 に答える