2010-03-03 11 views
5

atrybut Mam następujące XML:XSD - Ograniczanie wartości atrybutów do innego elementu wartość

<Content name="contentName1"> 
    <!-- Some sub elements here --> 
</Content> 

<Sequence Name="sequenceName1"> 
    <Content name="contentName1" /> 
    <!-- Some sub elements here --> 
</Sequence> 

z następującym XSD

<xs:element maxOccurs="unbounded" name="Content"> 
    <xs:complexType> 
     <xs:attribute name="Name" type="xs:string" use="required" /> 
     <!-- other definitions here --> 
    </xs:complexType> 
</xs:element> 

<xs:element maxOccurs="unbounded" name="Sequence"> 
    <xs:complexType> 
     <xs:sequence> 
      <xs:element maxOccurs="unbounded" name="Content"> 
       <xs:complexType> 
        <xs:attribute name="ContentName" type="xs:string" use="required" /> 
       </xs:complexType> 
      </xs:element> 
     </xs:sequence> 
     <xs:attribute name="Name" type="xs:string" use="required" /> 
    </xs:complexType> 
</xs:element> 

W XSD, jak mogę powiedzieć do atrybutu ContentName z Elementy zawartości Sekwencji akceptują tylko wartości zadeklarowane w elementach ContentName of Content?

np .: z powyższym XML, tylko ContentName1 zostanie zaakceptowany w Treści sekwencji.

Odpowiedz

2

Definicje ograniczeń tożsamości służą do wymuszania unikalnego klucza podstawowego i kluczy obcych. Najpierw należy zdefiniować kluczowy element dla elementu treści, a następnie użyć elementu keyref w wewnętrznym elemencie treści dla walidatora schematu, aby wymusić wspomniany warunek. poniższego linku ma kilka przykładów
Patrz także, również poradnik w xfront dla xsd obejmuje kilka przykładów -

http://www.w3.org/TR/xmlschema11-1/#Identity-constraint_Definition_details
http://www.xfront.com/files/xml-schema.html

-1

nie jestem dobry w XSD też, ale być może będzie zmiana <xs:attribute name="Name" type="xs:string" use="required" /> do <xs:attribute name="Name" type="contentNames" use="required" />

i tworzyć

<xs:simpleType name="contentNames" > 
    <xs:restriction base="xs:token"> 
     <xs:enumeration value="contentName1"/> 
     <xs:enumeration value="contentName2"/> 

     <xs:pattern value="contentName[1234567890][1234567890]"/> 
     <xs:enumeration value="contentName1"/> 
    </xs:restriction> 
    </xs:simpleType> 

dla

<xs:pattern value="contentName[1234567890][1234567890]"/> 

contentName1-99 ale nie wiem, czy można użyć <xs:enumeration/> też można spróbować

Powiązane problemy