0

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>
Brad
  • 157
  • 1
  • 9
  • 1
    Why did you remove the XSD and XML document from the question? Without them, the question cannot be answered. I have rolled back your edit. – Mathias Müller Jan 26 '16 at 17:32

1 Answers1

3

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.

kjhughes
  • 106,133
  • 27
  • 181
  • 240
  • Thank you so much for your help. It works! Totally thought I had to have it listed twice...now I know :) – Brad Jan 15 '16 at 20:40
  • You're welcome. Please [**accept**](http://meta.stackoverflow.com/q/5234/234215) this answer if it's helped. Also, please do not edit this answer by removing the corrected XML and XSD. Those edits have been rejected as harmful since they would detract from the completeness of the answer. Thanks. – kjhughes Jan 26 '16 at 17:55