Hi
i am using the code below to validate an xml using an xsd. The
corresponding xml and xsd have been attached. Despit the xml being valid
according to my editor, which validates against the xsd, i keep getting
this error with jdom:
org.jdom.input.JDOMParseException: Error on line 3: cvc-elt.1: Cannot
find the declaration of element 'email'.
As far as i know, my xsd is valid as well as the xml. Is there something
more i need to do in my code to have validation successfull?
code:
public void testXmlFormat() {
SAXBuilder builder = new SAXBuilder(true);
builder.setEntityResolver(new EntityResolver() {
public InputSource resolveEntity(String publicId, String
systemId)
throws SAXException, IOException {
//code to return the resource corresponding to
http://truc.much.com/email.xsd and printing on stderr the full url to
resource
//return null for other systemId;
}
});
try {
builder.setProperty( JAXPConstants.JAXP_SCHEMA_LANGUAGE,
JAXPConstants.W3C_XML_SCHEMA );
InputStream source =
getClass().getClassLoader().getResourceAsStream("email.xml");
InputSource is = new InputSource(source);
builder.build(is);
} catch (JDOMException e) {
e.printStackTrace();
fail("Exception thrown: "+e);
} catch (IOException e) {
e.printStackTrace();
fail("Exception thrown: "+e);
}
}