2013-10-07 2 views
0

XSD 스키마와 일치시키기 위해 xml이 필요하지만 일치하지 않습니다. XSD 스키마에서 무엇이 잘못 될 수 있습니까? xsi : type = "..."으로 올바르지 않은 것. 나는 뭔가를 놓칠지도 모른다. 희망이 무엇인지 잘못 알 수 있습니다. 나는 xsd를 온라인으로 확인하고 그것을 고치려고 노력했지만 그다지 효과가 없었다. 그래서 나는 포기하고 여기 쓰기로 결정합니다. 당신의 도움은 많이 감사합니다. 감사!xml이 xsd 스키마와 일치하지 않습니다 - 이유가 무엇입니까?

<?xml version="1.0" encoding="utf-8" ?> 
<ValidatorList xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > 
    <FieldValidator xsi:type="RequiredFieldValidator" PropertyName="BankTransactionNumber"> 
    <Next xsi:type="AsciiValidator" /> 
    </FieldValidator> 
    <FieldValidator xsi:type="RequiredFieldValidator" PropertyName="CurrencyIndicator"> 
    <Next xsi:type="StringLengthValidator" MaxLength="3" MinLength="3"> 
    <Next xsi:type="AlphaValidator" /> 
    </Next> 
</FieldValidator> 
</ValidatorList> 

XSD 스키마를이 XML에 대한 : 여기

은 XML이다

:이 같은 오류 메시지를 받았습니다

<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema"> 
<xs:element name="ValidatorList"> 
<xs:complexType> 
    <xs:sequence> 
    <xs:element name="FieldValidator" maxOccurs="unbounded" minOccurs="0"> 
     <xs:complexType mixed="true"> 
     <xs:sequence> 
      <xs:element name="Next" minOccurs="0"> 
      <xs:complexType mixed="true"> 
       <xs:sequence> 
       <xs:element name="Next" minOccurs="0"> 
        <xs:complexType mixed="true"> 
        <xs:sequence> 
         <xs:element name="Next" minOccurs="0"> 
         <xs:complexType> 
          <xs:simpleContent> 
          <xs:extension base="xs:string"> 
           <xs:attribute type="xs:byte" name="DecimalPlaces"/> 
          </xs:extension> 
          </xs:simpleContent> 
         </xs:complexType> 
         </xs:element> 
        </xs:sequence> 
        <xs:attribute type="xs:byte" name="MaxLength" use="optional"/> 
        <xs:attribute type="xs:byte" name="MinLength" use="optional"/> 
        <xs:attribute type="xs:string" name="AllowedValues" use="optional"/> 
        </xs:complexType> 
       </xs:element> 
       </xs:sequence> 
       <xs:attribute type="xs:byte" name="MaxLength" use="optional"/> 
       <xs:attribute type="xs:byte" name="MinLength" use="optional"/> 
       <xs:attribute type="xs:byte" name="DefaultValue" use="optional"/> 
      </xs:complexType> 
      </xs:element> 
      <xs:element type="xs:string" name="RegEx" minOccurs="0"/> 
     </xs:sequence> 
     <xs:attribute type="xs:string" name="PropertyName" use="optional"/> 
     <xs:attribute type="xs:byte" name="DefaultValue" use="optional"/> 
     <xs:attribute type="xs:string" name="TypeProperty" use="optional"/> 
     <xs:attribute type="xs:string" name="Regex" use="optional"/> 
     </xs:complexType> 
    </xs:element> 
    </xs:sequence> 
</xs:complexType> 
Error - Line 4, 39: org.xml.sax.SAXParseException; lineNumber: 4; columnNumber: 39; cvc-elt.4.2: Cannot resolve 'AsciiValidator' to a type definition for element 'Next'. 
Error - Line 6, 87: org.xml.sax.SAXParseException; lineNumber: 6; columnNumber: 87; cvc-elt.4.2: Cannot resolve 'RequiredFieldValidator' to a type definition for element 'FieldValidator'. 
Error - Line 7, 72: org.xml.sax.SAXParseException; lineNumber: 7; columnNumber: 72; cvc-elt.4.2: Cannot resolve 'StringLengthValidator' to a type definition for element 'Next'. 
Error - Line 8, 41: org.xml.sax.SAXParseException; lineNumber: 8; columnNumber: 41; cvc-elt.4.2: Cannot resolve 'AlphaValidator' to a type definition for element 'Next'. 
+0

그래서? 'AsciiValidator' 타입은 어디에 정의되어 있습니까? 나는 스키마에서 볼 수 없다. 아마도 모든'xsi : type'을'FieldValidator' (여러분이 정의한 유일한 것)로 바꾸어보십시오. –

+0

문자열 유형입니다. 잘 모르겠 xsd 스키마를 수정하는 방법 ... – user235973457

+0

'AsciiValidator'는 문자열 유형입니까? –

답변

2

xsi:type 속성은 당신이 스키마에 이름 유형의 계층 구조와 그 선언 된 형태 실제의 형태 파생 된 유형 중 하나입니다 기본 유형 만 인 요소가있을 때 사용하기위한 것입니다. 의 전형적인 예는 FieldValidatorNext 요소가 아니라 이름 유형보다는 익명 중첩 <complexType> 정의를 사용하여 선언 된 스키마에 address 아형 usAddress와 종류 및 ukAddress

것, 그래서 당신이에서 파생 된 다른 유형을 가질 수있는 방법은 없습니다 그래서 사용 감각이 xsi:type. 내가 최고 수준이라는 유형의 사용, 다른 스키마를 구성 할 다음 xsi:type 속성이 제대로 작동하고뿐만 아니라

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> 
    <xs:complexType name="FieldValidatorType"> 
    <xs:sequence> 
     <xs:element name="Next" type="FieldValidatorType" minOccurs="0" /> 
    </xs:sequence> 
    <xs:attribute name="PropertyName" type="xs:string" use="optional" /> 
    </xs:complexType> 

    <xs:complexType name="RequiredFieldValidator"> 
    <xs:complexContent> 
     <xs:extension base="FieldValidatorType" /> 
    </xs:complexContent> 
    </xs:complexType> 

    <xs:complexType name="AsciiValidator"> 
    <xs:complexContent> 
     <xs:extension base="FieldValidatorType" /> 
    </xs:complexContent> 
    </xs:complexType> 

    <xs:complexType name="StringLengthValidator"> 
    <xs:complexContent> 
     <xs:extension base="FieldValidatorType"> 
     <xs:attribute type="xs:byte" name="MaxLength" use="optional"/> 
     <xs:attribute type="xs:byte" name="MinLength" use="optional"/> 
     </xs:extension> 
    </xs:complexContent> 
    </xs:complexType> 

    <!-- and similar complexType declarations for the other types such as 
     AlphaValidator --> 

    <xs:element name="ValidatorList"> 
    <xs:complexType> 
     <xs:sequence> 
     <!-- define the FieldValidator element by referring to the base 
      FieldValidatorType, instance documents can use xsi:type to 
      substitute subtypes such as StringLengthValidator --> 
     <xs:element name="FieldValidator" maxOccurs="unbounded" minOccurs="0" 
        type="FieldValidatorType" /> 
     </xs:sequence> 
    </xs:complexType> 
    </xs:element> 
</xs:schema> 

을,이 (각각의 검증 유형에 서로 다른 측면을 묶는의 장점을 가지고 예를 들어 MaxLength이 아니라 StringLengthValidator에 유효) 및 Next 중첩의 임의의 깊이를 지원합니다 (유형 정의가 반복적이기 때문에).

+0

그것은 거의 작동하지만 하나의 오류 메시지가 있습니다 : 오류 - 줄 29, 103 : org.xml.sax.SAXParseException; lineNumber : 29; columnNumber : 103; src-element.3 : 요소 'FieldValidator'는 'type'특성과 'anonymous type'특성을 모두 가지며 요소 중 하나만 허용됩니다. – user235973457

+0

@ user235973457 오류 메시지가 말하는대로 - ValidatorList 내부의''에있는'type = "FieldValidatorType" "은 중첩 된''의 _instead이고 _as뿐만 아니라 _은 아닙니다. –

+0

@ user235973457 나는 하나의 완전한 ''을 제공함으로써 더 명확하게하려고 노력했다. –