S4s-elt-invalid-content.1: Element 'element' Is Invalid, Misplaced, Or Occurs Too Often

家住魔仙堡 提交于 2019-12-07 17:55:29

Your XML is fine, but your XSD has many errors:

  • A xs:complexType cannot have xs:element directly as a child; wrap it first in xs:sequence. (This is the error related to your current error message.)
  • A xs:attribute cannot appear within xs:sequence; move them outside but still within xs:complexType.
  • xsd: is not defined; you meant xs:.
  • The type of rating should be xs:decimal, not xs:integer
  • @binding should be @period to match your XML.

XSD

Here's your XSD will all errors repaired:

<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

  <xs:element name="authors">
    <xs:complexType>
      <xs:choice maxOccurs="unbounded">
        <xs:element name="coretext" type="coreTextType" />
        <xs:element name="author" type="authorType" />
      </xs:choice>
    </xs:complexType>
  </xs:element>

  <xs:complexType name="coreTextType">
    <xs:sequence>
      <xs:element name="author" type="authorType" maxOccurs="unbounded"/>
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="authorType">
    <xs:sequence>
      <xs:element name="name" type="xs:string" />
      <xs:element name="nationality" type="xs:string" />
      <xs:element name="rating" type="xs:decimal" />
    </xs:sequence>
    <xs:attribute name="id" type="xs:string" />
    <xs:attribute name="period" type="xs:string" />
  </xs:complexType>

</xs:schema>

It will now validate your XML sucessfully.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!