Error: Element must have no character or element information item [children], because the type's content type is empty

Error: Element must have no character or element information item [children], because the type's content type is empty

我似乎无法理解这个在线验证器告诉我的内容:

cvc-complex-type.2.1: Element 'characterPower' must have no character or element information item [children], because the type's content type is empty.

(我也得到了 'weakness' 元素的相同错误代码)

    <xs:element name="characterPower" type="xs:string">
        <xs:complexType>
            <xs:attribute name="origin" type="originType" use="required"/>
        </xs:complexType>
    </xs:element>
    <xs:element name="weakness">
        <xs:complexType>
            <xs:attribute name="lethality" type="lethalType" use="required"/>
        </xs:complexType>
    </xs:element>

    <xs:simpleType name="originType">
        <xs:restriction base="xs:string">
            <xs:enumeration value="alien" />
            <xs:enumeration value="radiation" />
            <xs:enumeration value="mutant" />
            <xs:enumeration value="skill" />
        </xs:restriction>
    </xs:simpleType>

    <xs:simpleType name="lethalType">
        <xs:restriction base="xs:string">
            <xs:enumeration value="major" />
            <xs:enumeration value="minor" />
        </xs:restriction>
    </xs:simpleType>

这是 XML 文档中与之相关的部分

        <characterPower origin="mutant">Weapon Expertise, Healing Factor, Master Martial Artist and Assassin</characterPower>
        <weakness lethality="minor">Poor Mental State</weakness>

如有任何帮助,我们将不胜感激。

要允许 characterPower 都具有 origin 属性 字符串内容,通过 xs:simpleContent 扩展 xs:string 像这样:

  <xs:element name="characterPower">
    <xs:complexType>
      <xs:simpleContent>
        <xs:extension base="xs:string">
          <xs:attribute name="origin" type="originType" use="required"/>
        </xs:extension>
      </xs:simpleContent>
    </xs:complexType>
  </xs:element>

您可以对 weakness 元素执行类似的操作。