ajj
ajj

Reputation: 127

Why do I keep getting an attribute error in my XML document?

Im new to XML and keep getting the error below:

Element 'topBilledActors' is based on a simple type definition. Attribute 'ids' is not defined in the schema instance namespace (xsi).

The code for my documents is below:

<!--lib.xsd-->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"xmlns="http://www.superstarmovies.com/library" targetNamespace="http://www.superstarmovies.com/library">
<!--actorID-->
<xs:simpleType name="actorID">
    <xs:restriction base="xs:ID">
        <xs:pattern value="a[0-9]{4}"/>
    </xs:restriction>
</xs:simpleType>
<!--actorIDREF-->
<xs:simpleType name="actorIDREF">
    <xs:restriction base="xs:IDREF">
        <xs:pattern value="a[0-9]{4}"/>
    </xs:restriction>
</xs:simpleType>
<xs:simpleType name="actorIDREFlist">
    <xs:list itemType="actorIDREF"/>
</xs:simpleType>
<!--movieID-->
<xs:simpleType name="movieID">
    <xs:restriction base="xs:ID">
        <xs:pattern value="m[0-9]{4}-[0-9]{3}"/>
    </xs:restriction>
</xs:simpleType>
<!--movieIDREF-->
<xs:simpleType name="movieIDREF">
    <xs:restriction base="xs:IDREF">
        <xs:pattern value="m[0-9]{4}-[0-9]{3}"/>
    </xs:restriction>
</xs:simpleType>
<!--rankType-->
<xs:simpleType name="rankType">
    <xs:restriction base="xs:integer">
        <xs:minInclusive value="1"/>
        <xs:maxInclusive value="50"/>
    </xs:restriction>
</xs:simpleType>
<!--enumerated Yes/No-->
<xs:simpleType name="yes_no">
    <xs:restriction base="xs:string">
        <xs:enumeration value="yes"/>
        <xs:enumeration value="no"/>
    </xs:restriction>
</xs:simpleType>
<!--genreType-->
<xs:simpleType name="genreName">
    <xs:restriction base="xs:string">
        <xs:enumeration value="action"/>
        <xs:enumeration value="comedy"/>
        <xs:enumeration value="drama"/>
        <xs:enumeration value="fantasy"/>
    </xs:restriction>
</xs:simpleType>
<!--roleType-->
<xs:complexType name="roleType">
        <xs:attribute name="character" type="xs:string" use="required"/>
        <xs:attribute name="movie" type="movieIDREF" use="required"/>
    </xs:complexType>
</xs:schema>


<!--catalog.xsd--> 
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:lib="http://www.superstarmovies.com/library" xmlns="http://www.superstarmovies.com/catalog" targetNamespace="http://www.superstarmovies.com/catalog">
<xs:import namespace="http://www.superstarmovies.com/library" schemaLocation="lib.xsd"/>
<xs:element name="catalog">
    <xs:complexType>
        <xs:all>
            <xs:element ref="actor" minOccurs="0"/>
            <xs:element ref="movie" minOccurs="0"/>
        </xs:all>
    </xs:complexType>
</xs:element>
<!--actor type-->
<xs:element name="actor">
    <xs:complexType>
        <xs:sequence>
            <xs:element ref="name"/>
            <xs:element ref="date"/>
            <xs:element ref="birthplace"/>
            <xs:element ref="role"/>
        </xs:sequence>
        <xs:attribute ref="actor" use="required"/>
        <xs:attribute ref="oscarWinner" use="optional" default="no"/>
    </xs:complexType>
</xs:element>
<xs:element name="name" type="xs:string"/>
<xs:element name="birthplace" type="xs:string"/>
<xs:element name="date" type="xs:date"/>
<xs:element name="role" type="lib:roleType"/>
<xs:attribute name="actor" type="lib:actorID"/>
<xs:attribute name="oscarWinner" type="lib:yes_no"/>
<!--movie type-->
<xs:element name="movie">
    <xs:complexType>
        <xs:sequence>
            <xs:element ref="title"/>
            <xs:element ref="year"/>
            <xs:element ref="length"/>
            <xs:element ref="topBilledActors"/>
        </xs:sequence>
        <xs:attribute name="id" use="required"/>
        <xs:attribute name="genre" use="required"/>
        <xs:attribute name="earningsRank" use="optional"/>
    </xs:complexType>
</xs:element>
<xs:element name="title" type="xs:string"/>
<xs:element name="year" type="xs:gYear"/>
<xs:element name="length" type="xs:time"/>
<xs:element name="topBilledActors" type="lib:actorIDREFlist"/>
<xs:attribute name="id" type="lib:movieID"/>
<xs:attribute name="genre" type="lib:genreName"/>
<xs:attribute name="earningsRank" type="lib:rankType"/>
</xs:schema>


<!--catalog.xml-->
<catalog xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.superstarmovies.com/catalog file:///C:/Users/akhanijow/Desktop/Assignment%201%20COMP/catalog.xsd" xmlns="http://www.superstarmovies.com/catalog">
<movie id="m2001-012" genre="drama">
    <title>Monster&apos;s Ball</title>
    <year>2001</year>
    <length>01:51:00</length>
    <topBilledActors ids="a0100 a0102"/>
</movie>
<actor id="a0100" oscarWinner="yes">
    <name>Halle Berry</name>
    <date>1966-08-14</date>
    <birthplace>Cleveland, OH</birthplace>
    <role character="Leticia Musgrove" movie="m2001-012"/>
    <role character="Storm" movie="m2000-035"/>
</actor>
<actor id="a0102" oscarWinner="yes">
    <name>Billy Bob Thornton</name>
    <role character="Hank Grotowski" movie="m2001-012"/>
</actor>
<movie id="m2000-035" genre="fantasy">
    <title>X-Men</title>
    <year>2000</year>
    <length>01:44:00</length>
    <topBilledActors ids="a0100 a0103"/>
</movie>
<actor id="a0103" oscarWinner="no">
    <name>Ian McKellen</name>
    <role character="Magneto" movie="m2000-035"/>
    <role character="Gandolf" movie="m2001-105"/>
    <role character="Gandolf" movie="m2003-107"/>
</actor>
<movie id="m2001-105" genre="action" earningsRank="17">
    <title>Lord of the Rings: The Fellowship of the Ring</title>
    <year>2001</year>
    <length>02:58:00</length>
    <topBilledActors ids="a0103"/>
</movie>
<movie id="m2003-107" genre="action" earningsRank="8">
    <title>Lord of the Rings: The Return of the King</title>
    <year>2003</year>
    <length>03:21:00</length>
    <topBilledActors ids="a0103"/>
</movie>
<actor id="a0101" oscarWinner="yes">
    <name>Tom Hanks</name>
    <date>1956-07-09</date>
    <birthplace>Concord, CA</birthplace>
    <role character="Captain John H. Miller" movie="m1998-102"/>
    <role character="Forrest Gump" movie="m1994-103"/>
    <role character="Andrew Beckett" movie="m1993-104"/>
</actor>
<movie id="m1998-102" genre="action" earningsRank="50">
    <title>Saving Private Ryan</title>
    <year>1998</year>
    <length>02:50:00 minutes</length>
    <topBilledActors ids="a0101 a0104"/>
</movie>
<actor id="a0104" oscarWinner="yes">
    <name>Matt Damon</name>
    <date>1970-10-08</date>
    <birthplace>Cambridge, MA</birthplace>
    <role character="Private James Francis Ryan" movie="m1998-102"/>
</actor>
<movie id="m1994-103" genre="comedy" earningsRank="14">
    <title>Forrest Gump</title>
    <year>1994</year>
    <length>02:22:00</length>
    <topBilledActors ids="a0101 a0105 a0106"/>
</movie>
<actor id="a0105" oscarWinner="yes">
    <name>Sally Field</name>
    <birthplace>Pasadena, CA</birthplace>
    <role character="Mrs. Gump" movie="m1994-103"/>
</actor>
<actor id="a0106">
    <name>Gary Sinise</name>
    <role character="Lt. Dan Taylor" movie="m1994-103"/>
    <role character="Ken Mattingly" movie="m1995-106"/>
</actor>
<movie id="m1993-104" genre="drama">
    <title>Philadelphia</title>
    <year>1993</year>
    <length>02:05:00</length>
    <topBilledActors ids="a0101 a0107"/>
</movie>
<movie id="m1995-106" genre="drama">
    <title>Apollo 13</title>
    <year>1995</year>
    <length>02:20:00</length>
    <topBilledActors ids="a0101 a0106"/>
</movie>
<actor id="a0107" oscarWinner="yes">
    <name>Denzel Washington</name>
    <role character="Joe Miller" movie="m1993-104"/>
</actor>
</catalog>

Upvotes: 0

Views: 718

Answers (1)

Alvin
Alvin

Reputation: 10458

You have this in your XML:

<topBilledActors ids="a0100 a0102"/>

But according to your schema definition topBilledActors is type of actorIDREFlist and does not define an attribute call ids.

You can delete the ids attribute in your XML, or change the schema definition to include that attribute.

Upvotes: 1

Related Questions