2017-03-29 3 views
0

"filter"블록을 포함하지 않는 XML 블록이 3 개 있거나 "invalidation"이있는 "filter"가 있으며 첫 번째 값은 "fixed1"또는 "fixed2"입니다. "fixed1"경우 : 다른 아무것도, "fixed2"이 순서 A1, A2, A3 경우 (아래 참조)XSD : 첫 번째 값에 따라이 XML의 유효성을 검사하는 방법

 <filter> 
      <invalidation>fixed1</invalidation> 
     </filter> 

     <filter> 
      <invalidation>fixed2</invalidation> 
      <A1>string...</A1> 
      <A2>string...</A2> 
      <A2>string...</A3> 
     </filter> 

방법이 유효성을 검사? xs : choice를 사용하는 몇 가지 해결책이 있다고 생각하지만 찾지 못했습니다.

내가 찾은 유일한 (가난한) 솔루션입니다 :

<?xml version="1.0" encoding="UTF-8"?> 
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> 
... 
<xs:simpleType name="invalidation"> 
    <xs:restriction base="xs:string"> 
    <xs:pattern value="fixed1|fixed2"/> 
    </xs:restriction> 
</xs:simpleType> 
... 
<xs:element name="filter" minOccurs="0"> 
    <xs:complexType> 
    <xs:all> 
     <xs:element name="invalidation" type="invalidation"/> 
     <xs:element name="A1" type="xs:string" minOccurs="0"/> 
     <xs:element name="A2" type="xs:string" minOccurs="0"/> 
     <xs:element name="A3" type="xs:string" minOccurs="0"/> 
    </xs:all> 
    </xs:complexType> 
</xs:element> 
+0

' '로 시도하십시오. http://stackoverflow.com/questions/24774554/xsd-1-1-xsalternative-xsassert –

+1

@ Jérôme, xs : alternative는 유형은 속성 값을 기반으로하므로 첫 번째 요소의 값을 기반으로 할 수 없습니다. –

답변

1

이는 XSD 1.0에서 수행 할 수 없습니다.

어설 션을 사용하여 XSD 1.1에서 수행 할 수 있습니다. 컨텐트 모델 (invalidation, (A1, A2, A3)?)을 사용하여 구조를 시퀀스로 정의한 다음 어설 션을 정의하십시오. not(invalidation='fixed1' and exists(A1)).

XSD 1.1은 Altova, Saxon 및 Apache Xerces에서는 지원되지만 Java 및 .NET의 기본 제공 유효성 검사기와 같은 다른 제품에서는 지원되지 않습니다.

+0

불행히도 내 유효성 검사기 "xmllint"는 XSD 1.0을 사용하는 것 같습니다. –