Error: Invalid content was found starting with element

Error: Invalid content was found starting with element

我无法验证我的文件。

这是我遇到的错误。

4: 14 cvc-complex-type.2.4.a: Invalid content was found starting with element 'AirportList'. One of '{"":Airport}' is expected.

47: 15 XML document structures must start and end within the same entity.

我将 post 我的 XML 文档代码和下面的 XSD 架构。我对此很陌生,所以我不确定自己做错了什么。我已经更改了文件的格式,但仍然出现相同的错误。

<?xml version="1.0"?>
<AirportList xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="filename.xsd"> 
<AirportList>
    <Airport>
        <name>Abbotsford International Airport</name>
        <community>Abbotsford</community>
        <province>British Columbia</province>
        <passengers>15</passengers>
    </Airport>
    <Airport>
        <name>Atlin Airport</name>
        <community>Atlin</community>
        <province>British Columbia</province>
        <passengers>15</passengers>
    </Airport>
    <Airport>
        <name>Atlin Water Aerodrome</name>
        <community>Atlin</community>
        <province>British Columbia</province>
        <passengers>15</passengers>
    </Airport>
    <Airport>
        <name>Baie-Comeau Water Aerodrome</name>
        <community>Baie-Comeau</community>
        <province>Quebec</province>
        <passengers>15</passengers>
    </Airport>
    <Airport>
        <name>Beaver Creek Airport</name>
        <community>Beaver Creek</community>
        <province>Yukon</province>
        <passengers>15</passengers>
    </Airport>
    <Airport>
        <name>Bedwell Harbour Water Aerodrome</name>
        <community>Bedwell Harbour</community>
        <province>British Columbia</province>
        <passengers>15</passengers>
    </Airport>
    <Airport>
        <name>Billy Bishop Toronto City Airport</name>
        <community>Toronto</community>
        <province>Ontario</province>
        <passengers>15</passengers>
    </Airport>
</AirportList>


<?xml version="1.0"?>
<!-- XSD Schema for simple_apoole33_IT_MUST_VALIDATE.xml -->

<xsd:schema xmlns:xsd=
    "http://www.w3.org/2001/XMLSchema">

    <xsd:element name="AirportList">
        <xsd:complexType>
        <xsd:sequence>

            <xsd:element name="Airport" 
                maxOccurs="unbounded">
                <xsd:complexType>
                <xsd:sequence>

                    <xsd:element name="name"type="xsd:string"/>

                    <xsd:element name="community"type="xsd:string"/>

                    <xsd:element name="province"type="xsd:string"/>

                    <xsd:element name="passengers"type="xsd:integer" minOccurs = "0"/>

                </xsd:sequence>
                </xsd:complexType>
            </xsd:element>

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

你们非常亲密。只需进行以下两项更改:

  1. 删除 XML 中多余的 AirportList 元素。
  2. 在 XSD 中的 @name@type 属性之间添加空格。

总而言之,那么你更正了XML,

<?xml version="1.0"?>
<AirportList xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:noNamespaceSchemaLocation="simple_apoole33.xsd"> 
  <Airport>
    <name>Abbotsford International Airport</name>
    <community>Abbotsford</community>
    <province>British Columbia</province>
    <passengers>15</passengers>
  </Airport>
  <Airport>
    <name>Atlin Airport</name>
    <community>Atlin</community>
    <province>British Columbia</province>
    <passengers>15</passengers>
  </Airport>
  <Airport>
    <name>Atlin Water Aerodrome</name>
    <community>Atlin</community>
    <province>British Columbia</province>
    <passengers>15</passengers>
  </Airport>
  <Airport>
    <name>Baie-Comeau Water Aerodrome</name>
    <community>Baie-Comeau</community>
    <province>Quebec</province>
    <passengers>15</passengers>
  </Airport>
  <Airport>
    <name>Beaver Creek Airport</name>
    <community>Beaver Creek</community>
    <province>Yukon</province>
    <passengers>15</passengers>
  </Airport>
  <Airport>
    <name>Bedwell Harbour Water Aerodrome</name>
    <community>Bedwell Harbour</community>
    <province>British Columbia</province>
    <passengers>15</passengers>
  </Airport>
  <Airport>
    <name>Billy Bishop Toronto City Airport</name>
    <community>Toronto</community>
    <province>Ontario</province>
    <passengers>15</passengers>
  </Airport>
</AirportList>

将根据您更正后的 XSD、

进行验证
<?xml version="1.0"?>
<!-- XSD Schema for simple_apoole33_IT_MUST_VALIDATE.xml -->
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <xsd:element name="AirportList">
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element name="Airport" 
                     maxOccurs="unbounded">
          <xsd:complexType>
            <xsd:sequence>
              <xsd:element name="name" type="xsd:string"/>
              <xsd:element name="community" type="xsd:string"/>
              <xsd:element name="province" type="xsd:string"/>
              <xsd:element name="passengers" type="xsd:integer" minOccurs="0"/>
            </xsd:sequence>
          </xsd:complexType>
        </xsd:element>
      </xsd:sequence>
    </xsd:complexType>
  </xsd:element>
</xsd:schema>

根据要求。