XML-Schema-ComplexType-Attribut Ref

Ich habe einige Schwierigkeiten mit der Zuordnung eines Attributs zu einem Element in meiner XML-schema. eine abgespeckte version von meinem schema ist unten:

<?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>

Erklärung: ich habe eine "DataRoot" element, das enthalten kann: 1 oder mehr "ValueSet" Elemente. Meine ValueSet-Typ enthält ein element, FishCount, das ist ein komplexer Typ, FishCountType.

FishCountType besteht aus den simpletype-SimpleFishCount, welche auf eine Dezimalzahl mit Einschränkungen, und ein Attribut, "interpolation".

Die test-XML-Datei, die ich verwende, ist unter:

<?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>

Mit diesem validator: http://www.utilities-online.info/xsdvalidation/#.UiC9UpK0KSo

Ich sehen, dass sowohl die XSD-und XML-gültig sind und gut ausgebildet, aber bei der Validierung der XML gegen XSD, bekomme ich diesen Fehler:

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'.

Es scheint der Verweis auf die 'interpolation' Attribut 'FishCountType" ist irgendwie falsch, aber ich kann ' T es herausfinden. Wenn ich das definieren der interpolation Attribut inline in FishCountType geben, und ändern Sie es in xs:integer, es funktioniert alles sehr schön.

Was mache ich hier falsch? Kann ich ein benutzerdefiniertes Attribut in dieser Weise?

Jede Hilfe dankbar, hab ich kratzte mich am Kopf fast kahl.

GELÖST Dank @Michael Kay

Dies ist, was ich kam mit:

    <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>
InformationsquelleAutor BeefyElbow | 2013-08-31
Schreibe einen Kommentar