Hey everyone,
I'm having a hard time figuring out why I can't seem to be able to validate my XML file using an XML schema in
java, although other tools (e.g. XMLlint) don't seem to have a problem with it. Besides, it even doesn't work with some example files I've found on the internet so I guess it really doesn't have anything to do with the XML file itself but rather with the way I'm attempting to validate it...
I've found several threads that mention similar problems on the net but no answer that could be of use to me :-|
Anyway, here goes. Here's the example XML file I'm using:
Here's the XSD:
And last but not least here's my Java code:
Upon calling this function, an exception is thrown as follows:
Exception in
thread "main" org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element 'Artist'.
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.handleStartElement(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.startElement(Unknown Source)
at com.sun.org.apache.xerces.internal.jaxp.validation.DOMValidatorHelper.beginNode(Unknown Source)
at com.sun.org.apache.xerces.internal.jaxp.validation.DOMValidatorHelper.validate(Unknown Source)
at com.sun.org.apache.xerces.internal.jaxp.validation.DOMValidatorHelper.validate(Unknown Source)
at com.sun.org.apache.xerces.internal.jaxp.validation.ValidatorImpl.validate(Unknown Source)
at javax.xml.validation.Validator.validate(Unknown Source)
at Test.testXMLValidation(Test.java:339)
at Test.main(Test.java:345)
I really don't get it. As far as I can tell (although I'm definitely not an expert with these things) the namespaces seem to be correctly set (as I said, the files seem to be valid from the point of view of other tools) and the top-level element should definitely be defined.
Does anyone happen to have an idea of what I'm doing wrong?
Thanks a lot in advance!
Eileen