2012-10-28 117 views
1
<xs:element name="qualificationRequired" type="ExtendedQualification"/> 
    <xs:complexType name="ExtendedQualification"> 
     <xs:complexContent> 
      <xs:extension base="qualifications"> 
       <xs:element name="other"> 
        <xs:element name="skills" type="xs:string"/> 
        <xs:element name="languages" type="xs:string"/> 
       </xs:element> 
      </xs:extension> 
     </xs:complexContent> 
    </xs:complexType> 
    </xs:sequence> 
</xs:complexType> //closes another complexType above 

我的驗證返回以下錯誤:XML架構複雜類型(自定義數據類型)錯誤

Validator Error: s4s-elt-must-match.1: The content of 'sequence' must match (annotation?, (element | group | choice | sequence | any)*). A problem was found starting at: complexType. LINE 2

Validator Error 2: src-resolve: Cannot resolve the name 'ExtendedQualification' to a(n) 'type definition' component. LINE 1

爲什麼會出現這種情況?

回答

2

<xs:sequence>作爲孩子不能包含<xs:complexType>。你必須把它放在別處。可以將它包裝在一個元素中,使其成爲嵌套類型,或者將其作爲全局類型直接放入<xs:schema>元素中。

正如錯誤消息說,你可以把一個<xs:sequence>內唯一的標籤:

  • <xs:element>
  • <xs:group>
  • <xs:choice>
  • <xs:sequence>
  • <xs:any>

此外,<xs:extension>不能將<xs:element>標籤標記爲兒童。您必須將它們包裝在<xs:sequence><xs:choice><xs:all>等中,具體取決於您想實現的目標。

最後,<xs:element>不能包含其他<xs:element>標籤作爲子標籤。你必須將它們包裝在一個序列/選項/全部等中,然後在<xs:complexType>中定義一個嵌套類型。或者將其全部移到外面以充當全球類型。

下面是一個有效的文檔,用於定義上面要做的事情。儘管我對整個文檔沒有深入瞭解,但可能需要根據上下文進行調整。

<xs:schema version="1.0" 
     xmlns:xs="http://www.w3.org/2001/XMLSchema" 
     elementFormDefault="qualified"> 
<xs:complexType name="blah"> <!-- You said there was a complexType open, I added its opening tag and gave it a placeholder name -->   
    <xs:sequence>    
     <xs:element name="qualificationRequired" type="ExtendedQualification"/>    
    </xs:sequence> 
</xs:complexType> 
<xs:complexType name="ExtendedQualification"> <!-- the complexType is now removed from your sequence and is a global type--> 
    <xs:complexContent> 
     <xs:extension base="qualifications"> 
      <xs:sequence> <!-- you can't have an element here, you must wrap it in a sequence, choice, all, etc. I chose sequence as it seems to be what you meant --> 
       <xs:element name="other"> 
        <xs:complexType> <!-- same here, an element can't contain other element tags as children. For a complex element, you need a complexType. I defined it as a nested type --> 
         <xs:sequence> <!-- even complexType can't have element tags as children, again, I used a sequenct --> 
          <xs:element name="skills" type="xs:string"/> 
          <xs:element name="languages" type="xs:string"/> 
         </xs:sequence> 
        </xs:complexType> 
       </xs:element> 
      </xs:sequence> 
     </xs:extension> 
    </xs:complexContent> 
</xs:complexType> 
</xs:schema> 
+0

非常感謝你:) – user1780609