I am newby of XML.
I using Apache Commons XMLConfiguration for my configuration.
I need a schema based validation.
The xsd is locateded in the resources folder of my java project.
The xml and xsd are not located in the same location.
Following the documentation (that report only an example with DTD). I produce the following code:
URL urlXsd = getClass().getResource("config.xsd");
DefaultEntityResolver resolver = new DefaultEntityResolver();
resolver.registerEntityId("configuration", urlXsd);
XMLConfiguration xmlConfig = new XMLConfiguration();
xmlConfig.setEntityResolver(resolver);
xmlConfig.setSchemaValidation(true);
xmlConfig.load(new File("config.xml"));
I get following exception:
Caused by: org.xml.sax.SAXParseException; lineNumber: 2; columnNumber: 16; cvc-elt.1: Cannot find the declaration of element 'configuration'.
My config.xsd:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:element name="configuration">
<xs:complexType>
<xs:sequence>
<xs:element name="reader">
</xs:element>
<xs:element name="writer">
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
My config.xml
<?xml version="1.0" encoding="ISO-8859-1" ?>
<configuration>
<reader>
</reader>
<writer>
</writer>
</configuration>
Can anyone help me?