具有属性的复杂类型的xml架构

具有属性的复杂类型的xml架构,xml,web,Xml,Web,我正在尝试为此元素创建xml架构 <shoesize country="yes">35</shoesize> 您必须分两个阶段进行,首先定义一个命名的顶级simpleType,以限制内容(将其放在所有现有xs:element声明之外,直接放在xs:schema下) 这将允许任何小于等于49的整数值,因此-500是有效值。从xs:nonNegativeInteger开始限制可能更合适,而不是xs:integer当我尝试验证它时,我得到了2个EER…s4s att必须出现:

我正在尝试为此元素创建xml架构

<shoesize country="yes">35</shoesize>

您必须分两个阶段进行,首先定义一个命名的顶级
simpleType
,以限制内容(将其放在所有现有
xs:element
声明之外,直接放在
xs:schema
下)


这将允许任何小于等于49的整数值,因此
-500
是有效值。从
xs:nonNegativeInteger
开始限制可能更合适,而不是
xs:integer

当我尝试验证它时,我得到了2个EER…s4s att必须出现:属性“name”必须出现在元素“complexType”中。和cvc elt.1.a:找不到元素“shoesize”的声明。@Stribor进行了编辑,以更清楚地表明命名的
simpleType
必须位于架构的顶层,而不是在现有的
序列中。
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="shoesize">
  <xs:complexType>
    <xs:simpleContent>
      <xs:extension base="xs:integer">
       <xs:attribute name="country" type="xs:string"  />
    </xs:extension>
   </xs:simpleContent>
  </xs:complexType>
</xs:element>
</xs:schema>
<xsd:sequence>
        <xsd:element name="something" type="xsd:string"/> 
        <xsd:element name="something else" type="xsd:string"/> 
        ......
        ......
        code above
        ....
        ...
</xsd:sequence>
s4s-elt-must-match.1: The content of 'sequence' must match (annotation?, (element | group | choice | sequence | any)*). 
<xs:simpleType name="lessThanFifty">
  <xs:restriction base="xs:integer">
    <xs:maxExclusive value="50" />
  </xs:restriction>
</xs:simpleType>
<xs:element name="shoesize">
 <xs:complexType>
  <xs:simpleContent>
   <xs:extension base="lessThanFifty">
    <xs:attribute name="country">
     <!-- you might want to pull this out into a top-level type if you
          have other yes/no attributes elsewhere in the schema -->
     <xs:simpleType>
      <xs:restriction base="xs:string">
       <xs:enumeration value="yes" />
       <xs:enumeration value="no" />
      </xs:restriction>
     </xs:simpleType>
    </xs:attribute>
   </xs:extension>
  </xs:simpleContent>
 </xs:complexType>
</xs:element>