I have an XML file that stores movies and their actors. There are 2 movie elements (+ their movieID attribute) that contain 2 actorID each. Each actorID also contains known_for/movies/movie
that also has a movieID.
I have managed to make "the main" movieID to be unique and actorID to be unique within that movieID. However, I also want to make movieID inside known_for/movies/movie
element to be unique within their corresponding actorID. I am a bit confused on where do I need to define unique id for the
known_for/movies/movie movieID
It probably has to go somewhere inside <xs:element name="movies
, I'm just not too sure where exactly.
This is my XML file
<?xml version="1.0" encoding="UTF-8"?>
<movies
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="test.xsd">
<movie movieID="1">
<title>Movie 1</title>
<cast>
<actors>
<actor actorID="1">
<name>Jack</name>
<known_for>
<movies>
<movie movieID="1">Movie 1</movie>
<movie movieID="2">Movie 2</movie>
<movie movieID="3">Movie 3</movie>
</movies>
</known_for>
</actor>
<actor actorID="2">
<name>James</name>
<known_for>
<movies>
<movie movieID="1">Movie 1</movie>
<movie movieID="2">Movie 2</movie>
<movie movieID="3">Movie 3</movie>
</movies>
</known_for>
</actor>
</actors>
</cast>
</movie>
<movie movieID="2">
<title>Movie 2</title>
<cast>
<actors>
<actor actorID="1">
<name>Jack</name>
<known_for>
<movies>
<movie movieID="1">Movie 1</movie>
<movie movieID="2">Movie 2</movie>
<movie movieID="3">Movie 3</movie>
</movies>
</known_for>
</actor>
<actor actorID="2">
<name>James</name>
<known_for>
<movies>
<movie movieID="1">Movie 1</movie>
<movie movieID="2">Movie 2</movie>
<movie movieID="3">Movie 3</movie>
</movies>
</known_for>
</actor>
</actors>
</cast>
</movie>
</movies>
This is my schema
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified"
attributeFormDefault="unqualified">
<xs:element name="movies">
<xs:complexType>
<xs:sequence>
<xs:element name="movie" type="movieType" maxOccurs="unbounded">
<xs:unique name="unique_actorID">
<xs:selector xpath="cast/actors/actor"/>
<xs:field xpath="@actorID"/>
</xs:unique>
</xs:element>
</xs:sequence>
</xs:complexType>
<xs:unique name="unique_movieID">
<xs:selector xpath="movie"/>
<xs:field xpath="@movieID"/>
</xs:unique>
</xs:element>
<xs:complexType name="movieType">
<xs:sequence>
<xs:element name="title" type="xs:string"/>
<xs:element name="cast" type="castType"/>
</xs:sequence>
<xs:attribute name="movieID" type="xs:integer" use="required"/>
</xs:complexType>
<xs:complexType name="castType">
<xs:sequence>
<xs:element name="actors" type="actorsAll">
</xs:element>
</xs:sequence>
</xs:complexType>
<xs:complexType name="actorsAll">
<xs:sequence>
<xs:element name="actor" type="actorType" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="actorType">
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="known_for" type="known_forGroup" minOccurs="0"/>
</xs:sequence>
<xs:attribute name="actorID" type="xs:integer" use="required"/>
</xs:complexType>
<xs:complexType name="known_forGroup">
<xs:sequence>
<xs:element name="movies" type="known_forType"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="known_forType">
<xs:sequence>
<xs:element name="movie" type="known_forMovies" maxOccurs="unbounded">
</xs:element>
</xs:sequence>
</xs:complexType>
<xs:complexType name="known_forMovies">
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="movieID" type="xs:integer"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:schema>
I have fixed the problem by adding unique id to the "known_for" element located inside the "actorType"