Brad
Brad

Reputation: 157

Error: Invalid content was found starting with element

I am having trouble getting my files to validate.

Here are the errors that I am getting.

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.

I will post both my XML document code and my XSD schema below. I'm new to this, so I'm not sure what I'm doing wrong. I have changed the formatting of my files around but I still get the same errors.

<?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>

Upvotes: 0

Views: 7112

Answers (1)

kjhughes
kjhughes

Reputation: 111541

You were very close. Just make these two changes:

  1. Eliminate the extra AirportList element in your XML.
  2. Add spaces between your @name and @type attributes in your XSD.

Altogether, then your corrected 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>

will validate against your corrected 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>

as requested.

Upvotes: 3

Related Questions