2014-02-17 6 views
0

열 id 특성을 통해 행 참조 열이있는 스키마를 만들려고합니다.XML 스키마의 ref 사용

<?xml version="1.0" encoding="ISO-8859-1" ?> 
<mapping xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 

    <rows> 
     <row> 
      <column id="123" /> 
      <column id="124" /> 
     </row> 
     <row> 
      <column id="123" /> 
      <column id="124" /> 
     </row> 
    </rows> 

    <columns> 
     <column id="123"> 
      <name>Apple</name> 
     </column> 

     <column id="124"> 
      <name>Banana</name> 
     </column> 
    </columns> 

</mapping> 

내 XSD는 다음과 같습니다 열이 난 행 요소에서 열 ID를 참조 할 수 있도록 나는 다음과 같은 XML 스키마를 만들려면 어떻게해야합니까

을 찾을 수 없기 때문에 다음 XML 및 XSD 유효성을 검사하지 않습니다 이하지만 그것이 열 참조 찾을 수 없습니다 ... 작동하지 않습니다

당신의 스키마가 몇 가지 사소한 문제가
<?xml version="1.0" encoding="ISO-8859-1"?> 
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> 

<xsd:element name="mapping"> 
    <xsd:complexType> 
     <xsd:sequence> 
      <xsd:element name="rows" type="Rows" minOccurs="0" maxOccurs="1"/> 
      <xsd:element name="columns" type="Columns" minOccurs="0" maxOccurs="1"/> 
     </xsd:sequence> 
    </xsd:complexType>  
    <xsd:key name="PKeyColumn"> 
     <xsd:selector xpath="columns/column"/> 
     <xsd:field xpath="@id"/> 
    </xsd:key>  
    <xsd:keyref name="FKeyColumn" refer="PKeyColumn"> 
     <xsd:selector xpath="rows/row/column"/> 
     <xsd:field xpath="@id"/> 
    </xsd:keyref> 
</xsd:element> 

<xsd:complexType name="Row"> 
    <xsd:sequence> 
     <xsd:element ref="column"> 
      <xsd:complexType> 
       <xsd:attribute name="id" use="required" type="xsd:integer" /> 
      </xsd:complexType> 
     </xsd:element> 
    </xsd:sequence> 
</xsd:complexType> 

<xsd:complexType name="Rows"> 
    <xsd:sequence> 
     <xsd:element name="row" type="Row" minOccurs="1" maxOccurs="unbounded"> 
      <xsd:unique name="UKeyColumn"> 
       <xsd:selector xpath="column"/> 
       <xsd:field xpath="@id"/> 
      </xsd:unique> 
     </xsd:element> 
    </xsd:sequence> 
</xsd:complexType> 

<xsd:complexType name="Columns"> 
    <xsd:sequence> 
     <xsd:element name="column" type="Column" minOccurs="1" maxOccurs="unbounded"/> 
    </xsd:sequence> 
</xsd:complexType> 

<xsd:complexType name="Column"> 
    <xsd:sequence> 
     <xsd:element name="name" type="xsd:string" minOccurs="1" maxOccurs="1"/> 
    </xsd:sequence> 
    <xsd:attribute name="id" type="xsd:integer" /> 
</xsd:complexType> 

</xsd:schema> 
+0

지금까지 작성한 스키마를 표시 할 수 있습니까? –

+0

원래 질문에 추가했습니다 – user3319681

답변

0

-에서 element ref="column"을 유형은 필요가 name 대신 ref 될를하고, maxOccurs이 1보다 커야합니다 (기본값).

<xsd:complexType name="Row"> 
    <xsd:sequence> 
     <xsd:element name="column" maxOccurs="unbounded"> 

I 이러한 에러를 수정 한 후, 모든 것이 잘 유효화하고 상호 참조 요건은 (a row에서 언급 된 모든 열 ID가 columns 섹션에서 하나와 일치해야한다는)에 keykeyref하여 음식을 장만 .

+0

하지만 ref를 사용하여 열에 대한 참조라는 생각을 적용하고 싶습니다. Isnt 그게 뭐야? – user3319681

+0

@ user3319681 아니요, 'ref'는 스키마의 다른 곳에서 최상위'element '선언을 가리키는 데 사용됩니다. 'key'와'keyref' 쌍은 상호 참조 제약 조건을 강제하는 것으로, 이미 맞습니다. "124"참조 중 하나를 "125"로 변경하면 유효성 검사 오류가 발생합니다. –

+0

그렇다면 원래의 의도대로라면 스키마 ("ref"제외)를 사용하는 것이 정확한 접근법이라고 할 수 있습니까? – user3319681