XML Schema Validation : Cannot find the declaration of element
Thanks to everyone above, but this is now fixed. For the benefit of others the most significant error was in aligning the three namespaces as suggested by Ian.
For completeness, here is the corrected XML and XSD
Here is the XML, with the typos corrected (sorry for any confusion caused by tardiness)
<?xml version="1.0" encoding="UTF-8"?>
<Root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="urn:Test.Namespace"
xsi:schemaLocation="urn:Test.Namespace Test1.xsd">
<element1 id="001">
<element2 id="001.1">
<element3 id="001.1" />
</element2>
</element1>
</Root>
and, here is the Schema
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="urn:Test.Namespace"
xmlns="urn:Test.Namespace"
elementFormDefault="qualified">
<xsd:element name="Root">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="element1" maxOccurs="unbounded" type="element1Type"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:complexType name="element1Type">
<xsd:sequence>
<xsd:element name="element2" maxOccurs="unbounded" type="element2Type"/>
</xsd:sequence>
<xsd:attribute name="id" type="xsd:string"/>
</xsd:complexType>
<xsd:complexType name="element2Type">
<xsd:sequence>
<xsd:element name="element3" type="element3Type"/>
</xsd:sequence>
<xsd:attribute name="id" type="xsd:string"/>
</xsd:complexType>
<xsd:complexType name="element3Type">
<xsd:attribute name="id" type="xsd:string"/>
</xsd:complexType>
</xsd:schema>
Thanks again to everyone, I hope this is of use to somebody else in the future.
cvc-elt.1: Cannot find the declaration of element 'Root'. [7]
Your schemaLocation
attribute on the root element should be xsi:schemaLocation
, and you need to fix it to use the right namespace.
You should probably change the targetNamespace
of the schema and the xmlns
of the document to http://myNameSpace.com
(since namespaces are supposed to be valid URIs, which Test.Namespace
isn't, though urn:Test.Namespace
would be ok). Once you do that it should find the schema. The point is that all three of the schema's target namespace, the document's namespace, and the namespace for which you're giving the schema location must be the same.
(though it still won't validate as your <element2>
contains an <element3>
in the document where the schema expects item
)