Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Validation error: cvc-elt.1: Cannot find the declaration of element

843834Sep 1 2006 — edited Feb 5 2008
I use JAXP to do XML Parsing and validation. I use DOM and not SAX.
My code is as follows:
SchemaFactory schemaFactory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
File schemaLocation = new File("C:\\config\\JMS_properties.xsd");
Schema schema = schemaFactory.newSchema(schemaLocation);
		
// Create the validator
Validator validator = schema.newValidator();
		
// Add an error handler to the validator
JMSErrorHandler errorHandler = new JMSErrorHandler();
validator.setErrorHandler(errorHandler);
		
// Create the dom factory
DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
		
// Set the namespace property
domFactory.setNamespaceAware(true);
		
// Create the document builder
DocumentBuilder builder = domFactory.newDocumentBuilder();
		
// Parse the xml file
Document doc = builder.parse(xmlFile);
		
// Create the dom source and destination
// The destination will contain the doc augmented with the default attribute/element
DOMSource source = new DOMSource(doc);
DOMResult result = new DOMResult();
		
// Validate and augment the source
validator.validate(source, result);
		
// Error checking
if ( errorHandler.validationError == true ) {
    // errors occured during the parsing
    System.out.println("XML file is not valid");
    System.exit(1);
} 
		
// Get the augmented document
this.augmented = (Document) result.getNode();
When executing my code, I got:
Validation error: cvc-elt.1: Cannot find the declaration of element 'JMSProperties'

But the xml file has this element in it so I do not understand the meaning of that error.

??????
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 4 2008
Added on Sep 1 2006
5 comments
1,290 views