。私は可能性を説明するために、別の方法を示します。
何があっても、新しいタイプを使用する必要があります。
最初のアプローチでは、アトリビュートのないパーティクルではなく、すべてのパーティクルとアトリビュートをベースタイプにすることを前提としています(後者のソリューションは、制限の)。ここでの制限がなぜ役立たないのかについては、XSDを見て理解しやすいはずです。
<?xml version="1.0" encoding="utf-8" ?>
<!--XML Schema generated by QTAssistant/XSR Module (http://www.paschidev.com)-->
<xs:schema targetNamespace="http://tempuri.org/XMLSchema.xsd" elementFormDefault="qualified" xmlns="http://tempuri.org/XMLSchema.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexType name="TransactionType">
<xs:all minOccurs="0" maxOccurs="1">
<xs:element name="Status" type="xs:string" minOccurs="1" fixed ="N" maxOccurs ="1"/>
<xs:element name="Amount" type="xs:decimal" minOccurs ="1" maxOccurs ="1"/>
</xs:all>
<xs:attribute name="type" type="xs:string"/>
</xs:complexType>
<xs:complexType name="DebitTransactionType">
<xs:complexContent>
<xs:restriction base="TransactionType">
<xs:all>
<xs:element name="Status" type="xs:string" minOccurs="1" fixed ="N" maxOccurs ="1"/>
<xs:element name="Amount" type="xs:decimal" minOccurs ="1" maxOccurs ="1"/>
</xs:all>
<xs:attribute name="type" type="xs:string" fixed="D"/>
</xs:restriction>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="CreditTransactionType">
<xs:complexContent>
<xs:restriction base="TransactionType">
<xs:all>
<xs:element name="Status" type="xs:string" minOccurs="1" fixed ="N" maxOccurs ="1"/>
<xs:element name="Amount" type="xs:decimal" minOccurs ="1" maxOccurs ="1"/>
</xs:all>
<xs:attribute name="type" type="xs:string" fixed="C"/>
</xs:restriction>
</xs:complexContent>
</xs:complexType>
<xs:element name="Transaction">
<xs:complexType>
<xs:sequence>
<xs:element name="Debit" type="DebitTransactionType"/>
<xs:element name="Credit" type="CreditTransactionType"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
有効なXML:
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<!-- Sample XML generated by QTAssistant (http://www.paschidev.com) -->
<Transaction xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://tempuri.org/XMLSchema.xsd">
<Debit type="D">
<Amount>1</Amount>
<Status>N</Status>
</Debit>
<Credit type="C">
<Amount>1</Amount>
<Status>N</Status>
</Credit>
</Transaction>
事制限とは、いくつかは、そのエレガントではないと言うでしょう...あなたはセット全体を「リピート」しなければならないということです。
基本タイプから属性を削除できる場合は、もう1つの方法として、拡張子を使用します。
<?xml version="1.0" encoding="utf-8" ?>
<!--XML Schema generated by QTAssistant/XSR Module (http://www.paschidev.com)-->
<xs:schema targetNamespace="http://tempuri.org/XMLSchema.xsd" elementFormDefault="qualified" xmlns="http://tempuri.org/XMLSchema.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexType name="TransactionType">
<xs:all minOccurs="0" maxOccurs="1">
<xs:element name="Status" type="xs:string" minOccurs="1" fixed ="N" maxOccurs ="1"/>
<xs:element name="Amount" type="xs:decimal" minOccurs ="1" maxOccurs ="1"/>
</xs:all>
</xs:complexType>
<xs:complexType name="DebitTransactionType">
<xs:complexContent>
<xs:extension base="TransactionType">
<xs:attribute name="type" type="xs:string" fixed="D"/>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="CreditTransactionType">
<xs:complexContent>
<xs:extension base="TransactionType">
<xs:attribute name="type" type="xs:string" fixed="C"/>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:element name="Transaction">
<xs:complexType>
<xs:sequence>
<xs:element name="Debit" type="DebitTransactionType"/>
<xs:element name="Credit" type="CreditTransactionType"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
...それは難しい要件ではない場合、私は属性を削除します...あなたは属性の値が固定され、要素の名前に結び付けられているので、あなたには、いくつかの冗長を持っているようです