I have a very simple xsd which defines an element "cache"
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<xsd:schema xmlns="http://mysite/schema/cache"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://mysite/schema/cache">
<xsd:complexType name="objectType" abstract="false">
<xsd:attribute name="target" type="xsd:string">
</xsd:attribute>
</xsd:complexType>
<xsd:complexType name="cacheType">
<xsd:sequence>
<xsd:element name="object" type="xsd:string" maxOccurs="unbounded" />
</xsd:sequence>
</xsd:complexType>
<xsd:element name="cache" type="cacheType"></xsd:element>
</xsd:schema>
I have a spring config file with :
<?xml version="1.0" encoding="utf-8"?>
<objects xmlns="http://www.springframework.net"
xmlns:cache="http://mysite/schema/cache"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://mysite/schema/cache http://mysite/cache.xsd">
<description>
</description>
<cache:cache>
<cache:object target="site"/>
</cache:cache>
</objects>
During the call to
Spring.Objects.Factory.Xml.XmlObjectDefinitionReader.DoLoadObjectDefinitions at startup, I get the following error:
[XmlSchemaValidationException: The 'http://mysite/schema/cache:cache' element is not declared.]
This suggests that spring cant find my schema, but the xsd is available.
Any ideas why this isnt working?
You need to declare to Spring that your schema exists, See the appendix on schema authoring
Specifically section B.5. Registering the handler and the schema.
Spring uses two files to deal with schema discovery.
META-INF/spring.handlers contains a mapping of XML Schema URIs to namespace handler classes.
META-INF/spring.schemas contains a mapping of XML Schema locations (referred to along with the schema declaration in XML files that use the schema as part of the 'xsi:schemaLocation' attribute) to classpath resources.