2014-11-10 7 views
0

상위 요소 (직접/간접) 요소의 특성에 a가있는 경우 요소의 특성이 특정 값을 가질 수있는 XSD 구조를 정의 할 수 있습니까? 어떤 가치?XSD - 상위 요소의 특성 값을 기준으로 특성 값 유효성 검사

예 :

<root> 
    <child1 myAttr="true"> 
     <child2> 
      <child3 otherAttr="false" /> <!-- 'otherAttr' can only be 'false' if 'myAttr' is 'true' --> 
     </child2> 
    </child1> 
</root> 

의사 해결 방법 :

...을 'child3'복합 형의 정의 <rule condition="@otherAttr == true && //child1/@myAttr != false" />처럼 뭔가를 추가하려면

예 :

<?xml version="1.0" encoding="utf-8"?> 
<xs:schema elementFormDefault="qualified" 
     xmlns:xs="http://www.w3.org/2001/XMLSchema" 
     xmlns="http://My.Schema.Namespace" 
     targetNamespace="http://My.Schema.Namespace"> 

<xs:element name="root"> 
    <xs:sequence> 
     <xs:element name="child1" type="child1Type" /> 
    </xs:sequence> 
</xs:element> 

<xs:complexType name="child1Type"> 
    <xs:sequence> 
    <xs:element name="child2" type="child2Type" /> 
    </xs:sequence> 
    <xs:attribute name="myAttr" type="xs:boolean" use="optional" default="false" /> 
</xs:complexType> 

<xs:complexType name="child2Type"> 
    <xs:sequence> 
    <xs:element name="child3" type="child3Type" /> 
    </xs:sequence> 
</xs:complexType> 

<xs:complexType name="child3Type"> 
    <xs:attribute name="otherAttr" type="xs:boolean" use="optional" default="true" /> 
    <rule condition="@otherAttr == true && //child1/@myAttr != false" /> 
</xs:complexType> 
+0

같은 (http://stackoverflow.com/questions/ 것 2518384/xml-schema-to-restrict-one-field-on-another) – Dijkgraaf

+0

해당 질문의 기본 사항은이 질문에 대한 답을 제공하지 못합니다. 비슷한 문제가 다른 요구 사항 및 세부 사항. 질문은 IMO에 서기에 충분히 독특합니다. – travega

답변

2

임의의 종류의 교차 유효성 검사를 정의하려면 임의의 어설 션을 허용하는 XSD 1.1이 필요합니다. 어설 션은 어설 션이 배치 된 요소의 하위 트리에 대한 액세스 권한을 가지며 조상 개체에 대한 액세스 권한을 가지지 않으므로 사용자의 어설 션은 child1 요소로 이동해야합니다. 당신은 매우 명확 조건이 실제로 무엇인지 설명하지 않은,하지만의 중복 가능성 [XML 스키마가 다른 기반으로 하나 개의 필드를 제한]

<xs:assert test="if (@myAttr = 'true') then child2/child3/@otherAttr = 'false' else true()"/>