2013-03-14 4 views
1

여러분, 다음과 같은 도움이 필요합니다. 내 XML은 다음과 같습니다값으로 xsd 제한

<Images> 
    <Image ImageId="1" ImageFile="a.png"/> 
    <Image ImageId="2" ImageFile="b.png"/> 
    <Image ImageId="3" ImageFile="c.png"/> 
    <Image ImageId="4" ImageFile="d.png"/> 
    <Image ImageId="5" ImageFile="e.png"/> 
</Images> 
<Banners> 
    <Banner BannerId="1" ImageId="2"/> 
    <Banner BannerId="43" ImageId="3"/> 
    <Banner BannerId="45" ImageId="4"/> 
    <Banner BannerId="596" ImageId="2"/> 
    <Banner BannerId="6" ImageId="2"/> 
</Banners> 

내가 사진에 나오는 사람들에게 배너 요소에 ImageId 값을 제한 할 것 XSD를 작성해야합니다. 가능한가?

답변

1

예; 당신이 필요로하는 XML 스키마 구성 요소가 keyref/열쇠 :

<?xml version="1.0" encoding="utf-8"?> 
<!--XML Schema generated by QTAssistant/XML Schema Refactoring (XSR) Module (http://www.paschidev.com)--> 
<xsd:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> 
    <xsd:element name="sample"> 
     <xsd:complexType> 
      <xsd:sequence> 
       <xsd:element name="Images"> 
        <xsd:complexType> 
         <xsd:sequence> 
          <xsd:element maxOccurs="unbounded" name="Image"> 
           <xsd:complexType> 
            <xsd:attribute name="ImageId" type="xsd:unsignedByte" use="required"/> 
            <xsd:attribute name="ImageFile" type="xsd:string" use="required"/> 
           </xsd:complexType> 
          </xsd:element> 
         </xsd:sequence> 
        </xsd:complexType> 
       </xsd:element> 
       <xsd:element name="Banners"> 
        <xsd:complexType> 
         <xsd:sequence> 
          <xsd:element maxOccurs="unbounded" name="Banner"> 
           <xsd:complexType> 
            <xsd:attribute name="BannerId" type="xsd:unsignedShort" use="required"/> 
            <xsd:attribute name="ImageId" type="xsd:unsignedByte" use="required"/> 
           </xsd:complexType> 
          </xsd:element> 
         </xsd:sequence> 
        </xsd:complexType> 
       </xsd:element> 
      </xsd:sequence> 
     </xsd:complexType> 
     <xsd:key name="PK"> 
      <xsd:selector xpath="Images/Image"/> 
      <xsd:field xpath="@ImageId"/> 
     </xsd:key> 
     <xsd:keyref name="FK" refer="PK"> 
      <xsd:selector xpath="Banners/Banner"/> 
      <xsd:field xpath="@ImageId"/>  
     </xsd:keyref> 
    </xsd:element> 
</xsd:schema> 

샘플 오류 메시지 :

The key sequence '8' in Keyref fails to refer to some key. 
xsd-restriction-by-value.xml is XSD 1.0 invalid. 
+0

덕분에,이 작동합니다. 내 원래의 실수는 전체 경로 대신 ./Banner 및 ./Image를 사용하려는 시도였습니다. – atarno