XML スキーマの complexType に属性を割り当てる際に問題が発生しています。私のスキーマの縮小版は以下のとおりです。
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://xml-test.com"
xmlns="http://xml-test.com"
elementFormDefault="qualified">
<!--++++++++++ ELEMENT DEFINTIONS ++++++++++-->
<xs:element name="DataRoot" type="RootDataType"/>
<!--++++++++++ TYPE DEFINTIONS ++++++++++-->
<!-- Document Root -->
<xs:complexType name="RootDataType">
<xs:sequence minOccurs="1" maxOccurs="unbounded">
<xs:element name="ValueSet" type="ValuesType"/>
</xs:sequence>
<!-- Attributes -->
<xs:attribute name="index" type="xs:integer" use="required"/>
</xs:complexType>
<!-- Value Set Type: A type representing a series of data values -->
<xs:complexType name="ValuesType">
<xs:sequence minOccurs="1" maxOccurs="1">
<xs:element name="FishCount" type="FishCountType"/>
</xs:sequence>
<!-- Attributes -->
<xs:attribute name="catcher" type="xs:string" use="required"/>
</xs:complexType>
<!-- Simple Fish Count type -->
<xs:simpleType name="SimpleFishCountType">
<xs:restriction base="xs:decimal">
<xs:totalDigits value="3"/>
<xs:fractionDigits value="1"/>
</xs:restriction>
</xs:simpleType>
<!-- Fish Count type -->
<xs:complexType name="FishCountType">
<xs:simpleContent>
<xs:extension base="SimpleFishCountType">
<xs:attribute ref="interpolation"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
<!--++++++++++ ATTRIBUTE DEFINTIONS ++++++++++-->
<!-- Attribute to specify interpolation method -->
<xs:attribute name="interpolation">
<xs:simpleType>
<xs:restriction base="xs:integer">
<xs:minInclusive value="0"/>
<xs:maxInclusive value="1"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
説明: 1 つ以上の「ValueSet」要素を含むことができる「DataRoot」要素があります。私の ValueSet 型には、複雑な型である FishCountType である 1 つの要素、FishCount が含まれています。
FishCountType は、制限付きの 10 進数に基づく simpletype SimpleFishCount と、属性「補間」で構成されます。
私が使用しているテスト XML ファイルは次のとおりです。
<?xml version="1.0"?>
<DataRoot index="1"
xmlns="http://xml-test.com"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xml-test.com test-001.xsd">
<ValueSet catcher="CaptainBirdsEye">
<FishCount interpolation="0">12.3</FishCount>
</ValueSet>
</DataRoot>
このバリデーターの使用: http://www.utilities-online.info/xsdvalidation/#.UiC9UpK0KSo
XSD と XML の両方が有効で整形式であることがわかりますが、XSD に対して XML を検証すると、次のエラーが発生します。
Not valid.
Error - Line 9, 36: org.xml.sax.SAXParseException; lineNumber: 9; columnNumber: 36; cvc-complex-type.3.2.2: Attribute 'interpolation' is not allowed to appear in element 'FishCount'.
'FishCountType' の 'interpolation' 属性への参照が何か間違っているようですが、わかりません。FishCountType 型内で補間属性をインラインで定義し、それを xs:integer に変更すると、すべてうまく機能します。
ここで何が間違っていますか?この方法でカスタム属性を使用できますか?
どんな助けでも感謝します、私は頭をほとんど禿げました。
@Michael Kayのおかげで解決しました
これは私が行ったことです:
<xs:attributeGroup name="interpolation">
<xs:attribute name="interpolation">
<xs:simpleType>
<xs:restriction base="xs:integer">
<xs:minInclusive value="0"/>
<xs:maxInclusive value="1"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:attributeGroup>