2012-10-28 176 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