在 xsd 中一起使用扩展和普通属性

我正在尝试进行映射,我需要使用:


Config.xxx.yyy.KeyPair[z].normalAttribute

Config.xxx.yyy.KeyPair[z]@extendAttribute

KeyPair 可以使用 0 到 x 次


额外属性:KeyId、KeyType、ValidTo、Active

普通属性:PrivateKey、PublicKey

但是当我尝试在 C# 中加载 xsd 文件时抛出错误:


System.Xml.Schema.XmlSchemaException: The type attribute cannot be present with either simpleType or complexType.

这里显示了我是如何制作的缩短版本,但它根本不起作用:


<xs:element name="Config">

  <xs:complexType>

    <xs:all>

      <xs:element name="xxx">

        <xs:complexType>

          <xs:all>

            <xs:element name="EncryptionKeys" type="yyy"/>

          </xs:all>

        </xs:complexType>

      </xs:element>

    </xs:all>

  </xs:complexType>

</xs:element>


<xs:element name="yyy">

  <xs:complexType>

    <xs:sequence>

      <xs:element name="KeyPair" type="KeyPairExtraTypes" maxOccurs="unbounded" minOccurs="0">

        <xs:complexType>

          <xs:attributeGroup ref="KeyPairAttributes"/>

          <xs:attributeGroup ref="KeyPairExtraTypes"/>

        </xs:complexType>

      </xs:element>

    </xs:sequence>

  </xs:complexType>

</xs:element>


<xs:attributeGroup name="KeyPairAttributes">

  <xs:attribute name="PrivateKey" type="xs:string"/>

  <xs:attribute name="PublicKey" type="xs:string"/>

</xs:attributeGroup>


<xs:complexType name="KeyPairExtraTypes">

  <xs:simpleContent>

    <xs:extension base="xs:string">

      <xs:attribute type="xs:string" name="KeyId"/>

      <xs:attribute type="xs:string" name="KeyType" use="required"/>

      <xs:attribute type="xs:string" name="ValidTo" use="optional"/>

      <xs:attribute type="xs:bool" name="Active" use="required"/>

    </xs:extension>

  </xs:simpleContent>

</xs:complexType>


叮当猫咪
浏览 162回答 1
1回答

至尊宝的传说

解决方案很简单。<xs:element name="Config">&nbsp; &nbsp; <xs:complexType>&nbsp; &nbsp; &nbsp; &nbsp; <xs:all>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <xs:element name="xxx">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <xs:complexType>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <xs:all>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <xs:element name="EncryptionKeys">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <xs:complexType>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <xs:sequence>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <xs:element name="KeyPair" maxOccurs="unbounded">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <xs:complexType>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <xs:all>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <xs:element name="PublicKey" type="xs:string"/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <xs:element name="PrivateKey" type="xs:string"/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </xs:all>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <xs:attribute name="KeyId"/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <xs:attribute name="KeyType" type="xs:string" use="required"/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <xs:attribute name="ValidTo" type="xs:string"/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <xs:attribute name="Active" type="xs:boolean" use="required"/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </xs:complexType>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </xs:element>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </xs:sequence>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </xs:complexType>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </xs:element>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </xs:all>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </xs:complexType>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </xs:element>&nbsp; &nbsp; &nbsp; &nbsp; </xs:all>&nbsp; &nbsp; </xs:complexType></xs:element>
打开App,查看更多内容
随时随地看视频慕课网APP