2013-02-14 1 views
1

속성 값에 따라 단일 유형의 노드에 대해 특정 XSD 유효성 검사를해야합니다. XSD 1.1 및 xsd : alternative가 내 친구 여야합니다. XSD 1.1 대체 사용 문제

하지만 다음 (가장 간단한) 예와

는 :

<xsd:complexType name="BaseType"> 
    <xsd:attribute name="type" 
        type="xsd:string" 
        use="required" /> 
</xsd:complexType> 

<xsd:complexType name="NamedType"> 
    <xsd:complexContent> 
     <xsd:extension base="BaseType"> 
      <xsd:attribute name="path" 
          type="xsd:string" 
          use="required" /> 
     </xsd:extension> 
    </xsd:complexContent> 
</xsd:complexType> 

<xsd:complexType name="TaggedType"> 
    <xsd:complexContent> 
     <xsd:extension base="BaseType"> 
      <xsd:attribute name="tag" 
          type="xsd:string" 
          use="required" /> 
     </xsd:extension> 
    </xsd:complexContent> 
</xsd:complexType> 

<xsd:element name="MyRoot"> 
    <xsd:complexType> 
      <xsd:choice minOccurs="1"> 
      <xsd:element name="MyType" 
         type="BaseType"> 
       <xsd:alternative test="@type='Named'" 
           type="NamedType"/> 
       <xsd:alternative test="@type='Tagged'" 
           type="TaggedType"/> 
      </xsd:element> 
      </xsd:choice> 
    </xsd:complexType> 
</xsd:element> 

나는 XSD로드하고 (Qt는 4.7.4에서 QXmlSchema 클래스를 사용을하지만 이것이 XSD 문제보다는 Qt는 하나라고 생각) 다음 오류가 발생합니다.

오류 XSDError 알 수없는 위치, 93 줄 74 열 : 대체 요소의 테스트 특성에 잘못된 내용이 포함되어 있습니다 : {@ type = 'Named'}.

나는 대체 시험 조건 및 기타 합리적인 덜 합리적인 변화의 톤에서 "@type EQ '명명'"또한 시도 ... 아무도 통과하지 : 어떤 도움이 많이 주시면 감사합니다/

! 감사!

답변

1

Petru Gardea와 마찬가지로, XSD 스키마가 훌륭하다고 생각합니다. (더 중요한 것은 색슨도 그렇습니다).

문제는 XSD 프로세서가 XSD 1.1을 지원하지 않는다는 것입니다. QXmlSchema Class Reference에는 "이 클래스는 XML 스키마 1.0 사양을 따르는 스키마를 나타내는 데 사용됩니다." 오류 메시지는 아마도 (@type에 대해 불평하고 xsd : 대체로 잘못된 아이디어를 제공한다는 점에서) 조금 더 명확해질 수 있지만 일반적으로 소프트웨어가 처리 할 준비가되지 않은 상황을보고하는 오류 메시지에 종종 해당됩니다.

1

XSD가 나에게 잘 보입니다. QTAssistant (궁극적으로 Xerces 버전의 XSD 1.1을 기반으로합니다)에서 시도한 및 잘 작동합니다. 이 샘플 XML로

:

<?xml version="1.0" encoding="utf-8" standalone="yes"?> 
<!-- Sample XML generated by QTAssistant (http://www.paschidev.com) --> 
<MyRoot xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://tempuri.org/XMLSchema.xsd"> 
    <MyType type="Tagged"/> 
</MyRoot> 

내가 얻을 :

Error while loading [], line 4 position 25 
cvc-complex-type.4: Attribute 'tag' must appear on element 'MyType'. 
Document1.xml is XSD 1.1 invalid. 

이 XML로 :

<?xml version="1.0" encoding="utf-8" standalone="yes"?> 
<!-- Sample XML generated by QTAssistant (http://www.paschidev.com) --> 
<MyRoot xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://tempuri.org/XMLSchema.xsd"> 
    <MyType type="Named"/> 
</MyRoot> 

내가 얻을 :

Error while loading [], line 4 position 24 
cvc-complex-type.4: Attribute 'path' must appear on element 'MyType'. 
Document1.xml is XSD 1.1 invalid. 

제안 된대로 위의 내용을 수정하면 유효한 XML 결과가 생성됩니다. 귀하의 구문이 정확하므로 귀하의 XSD 프로세서만을 비난 할 수 있습니다.