元素 'sequence' 无效、放错位置或出现太频繁

Element 'sequence' is invalid, misplaced, or occurs too often

我在使用架构验证 XML 文件时出错。

s4s-elt-invalid-content.1: The content of '#AnonType_userusersroot' is invalid. Element 'sequence' is invalid, misplaced, or occurs too often. [25]

我的 XML 文件:

 <root>  
    <users>   
        <user code="10">
            <fullName>sandesh poudel</fullName>
            <sex>male</sex>
            <age>19</age>
            <phoneNo>239239</phoneNo>
            <address>Rasinkatu 13</address> 
            <title>owner</title> 
        </user>
        <user code ="20">
            <fullName>Surendra pandey</fullName>
            <sex>male</sex>
            <age>22</age>
            <phoneNo>3432</phoneNo>
            <address>kilo 13</address>
            <title>manager</title> 
        </user>
        <user code ="40">
            <fullName>sangam poudel</fullName>
            <sex>male</sex>
            <age>22</age>
            <phoneNo>239239</phoneNo>
            <address>sydney</address> 
            <title>Programmer</title> 
        </user>
    </users>> 
</root>

我的 XML 架构文件:

<xs:schema    xmlns:xs="http://www.w3.org/2001/XMLSchema"
              targetNamespace="http://www.w3schools.com"
              xmlns="http://www.w3schools.com"
              elementFormDefault="qualified">
    <xs:element name="root">
        <xs:complexType mixed="true">
            <xs:sequence maxOccurs="unbounded">
                <xs:element name="users">
                    <xs:complexType>
                        <xs:sequence maxOccurs="unbounded">

                            <xs:element name="user">


                                <xs:complexType mixed="true">
                                    <xs:attribute name="code" type="xs:string"/>
                                    <xs:sequence>

                                    <xs:element name="fullName" type="xs:string"/> 
                                    <xs:element name="sex" type="xs:string"/> 
                                    <xs:element name="age" type="xs:string"/> 
                                    <xs:element name="phoneNo" type="xs:string"/>
                                    <xs:element name="address" type="xs:string"/> 
                                    <xs:element name ="title" type="xs:string"/>
                                    </xs:sequence>
                                </xs:complexType>

                            </xs:element> <!-- name -->

                        </xs:sequence>
                    </xs:complexType>
                </xs:element>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
</xs:schema>

您需要对 XSD 进行两项更改:

  1. xs:attribute 声明移动到 下方 xs:sequence
  2. 从 XSD 中删除 xs:targetNamspace 因为没有使用命名空间 在 XML.

一共:

XSD

<xs:schema    xmlns:xs="http://www.w3.org/2001/XMLSchema"
              elementFormDefault="qualified">
  <xs:element name="root">
    <xs:complexType mixed="true">
      <xs:sequence maxOccurs="unbounded">
        <xs:element name="users">
          <xs:complexType>
            <xs:sequence maxOccurs="unbounded">
              <xs:element name="user">
                <xs:complexType mixed="true">
                  <xs:sequence>
                    <xs:element name="fullName" type="xs:string"/> 
                    <xs:element name="sex" type="xs:string"/> 
                    <xs:element name="age" type="xs:string"/> 
                    <xs:element name="phoneNo" type="xs:string"/>
                    <xs:element name="address" type="xs:string"/> 
                    <xs:element name ="title" type="xs:string"/>
                  </xs:sequence>
                  <xs:attribute name="code" type="xs:string"/>
                </xs:complexType>
              </xs:element> <!-- name -->
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>