No declaration found for element ' '
I'm new to working with XML and XSD files. What I'm trying to do is validate an xml file using a schema. This is the start of my XML file:
<?xml version="1.0" encoding="UTF-8"?>
<movies>
<doc id="000007">
<docid>000007</docid>
<title>#73, Shanthi Nivasa</title>
<year>2007</year>
<type>movie</type>
<colorinfos>
<colorinfo>Color</colorinfo>
</colorinfos>
<genres>
<genre>Musical</genre>
</genres>
<languages>
<language>Kannada</language>
</languages>
<countries>
<country>India</country>
</countries>
<releasedates>
<releasedate country="India">14 June 2007</releasedate>
</releasedates>
<directors>
<director>Sudeep</director>
</directors>
<composers>
<composer>Bharadwaj (I)</composer>
</composers>
<cast>
<credit>
<actor>Shivarajkumar</actor>
<role>Himself</role>
</credit>
<credit>
<actor>Sudeep</actor>
<role>Raghu</role>
</credit>
<credit>
<actor>Vishnuvardhan (I)</actor>
<role>Himself</role>
</credit>
</cast>
<plot>#73, Shanthi Nivasa - the littlest things in life that give peace and happiness in a home. Although #73, Shanthi Nivasa seems to have everything on the surface, it lacks the depth of peace. Amidst the constant family fights, Raghu enters the household as the new cook and brings the ingredient of peace with him. And mysteriously, he leaves. What will #73, Shanthi Nivasa do without Raghu? Will they be able to hold their family together without this unassuming cook's presence?</plot>
<url>http://localhost:8983/solr/movie.html?000007</url>
</doc>
</movies>
And this is the start of my schema:
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="movies">
<xs:complexType>
<xs:sequence>
<xs:element name="doc" maxOccurs="unbounded" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:short" name="docid"/>
<xs:element type="xs:string" name="title"/>
<xs:element type="xs:short" name="year"/>
<xs:element type="xs:string" name="type"/>
<xs:element name="colorinfos" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:string" name="colorinfo" maxOccurs="unbounded" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="editors" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:string" name="editor" maxOccurs="unbounded" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="genres" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:string" name="genre" maxOccurs="unbounded" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="keywords" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:string" name="keyword" maxOccurs="unbounded" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="languages" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:string" name="language" maxOccurs="unbounded" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="soundmixes" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:string" name="soundmix"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="countries">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:string" name="country" maxOccurs="unbounded" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="certificates" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element name="certificate" maxOccurs="unbounded" minOccurs="0">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute type="xs:string" name="country" use="optional"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="releasedates" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element name="releasedate" maxOccurs="unbounded" minOccurs="0">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute type="xs:string" name="country" use="optional"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="runningtimes" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element name="runningtime" maxOccurs="unbounded" minOccurs="0">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:short">
<xs:attribute type="xs:string" name="country" use="optional"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="directors" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:string" name="director" maxOccurs="unbounded" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="producers" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:string" name="producer" maxOccurs="unbounded" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="writers" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:string" name="writer" maxOccurs="unbounded" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="composers" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:string" name="composer" maxOccurs="unbounded" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="othercrew" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element name="credit" maxOccurs="unbounded" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:string" name="name"/>
<xs:element type="xs:string" name="job"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="cast" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element name="credit" maxOccurs="unbounded" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:string" name="actor"/>
<xs:element type="xs:string" name="role"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element type="xs:string" name="plot"/>
<xs:element type="xs:anyURI" name="url"/>
</xs:sequence>
<xs:attribute type="xs:short" name="id" use="optional"/>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
The error I get whenever I try to validate the file is:
Error at line 2, column 9: no declaration found for element 'movies'
The schema is auto-generated (I'm using XML Copy Editor). The XML and XSD files' syntax is also correct.
You have to somehow associate the XSD with the XML.
A common way to do this is to use noNamespaceSchemaLocation
for non-namespaced XML or schemaLocation
for namespaced XML. To use this approach, change
<movies>
to
<movies xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="try.xsd">
You can also use your validator tool's mechanism for specifying the association, but those mechanisms tend to be implementation-specific, whereas the above hint tends to work for all validators.
See also
- How to link XML to XSD using schemaLocation or noNamespaceSchemaLocation?
- How to reference a local XML Schema file correctly?