views:

12

answers:

0

In my program, I am generating a XML file, and need to validate that XML file against multiple schema's which(schema) are located on different URLs. Its required to validate that XML file against all schema in onetime only.

source fragment:-

// here source array contain the locations of schemas, located at diff servers.

Source [] source = { new StreamSource(new URL("http://localhost:8081/test1/testSchema1.xsd").openStream()), new StreamSource(new URL("http://ccr.internal.ericsson.com/test2/testSchema2.xsd").openStream())};

try { // Compile the schema, which loaded from schemaFileLocation. Schema schemaGrammar = schemaFactory.newSchema(source);

// Create a validator for schema. Validator configValidator = schemaGrammar.newValidator();

// set error handler with validator. SchemaValidator schemaValidator = new SchemaValidator(); configValidator.setErrorHandler(schemaValidator.new MessageHandler());

// validate xml instance against the grammar. configValidator.validate(new StreamSource(new File("xmlFile.xml"))); System.out.println("\n"); } catch (SAXException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); }

While running above code fragment, I am getting below error:-

org.xml.sax.SAXParseException: src-resolve: Cannot resolve the name 'xn:SubNetwork' to a(n) 'element declaration' component. at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source) at org.apache.xerces.util.ErrorHandlerWrapper.error(Unknown Source) at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source) at org.apache.xerces.impl.xs.traversers.XSDHandler.reportSchemaError(Unknown Source) at org.apache.xerces.impl.xs.traversers.XSDHandler.getGlobalDecl(Unknown Source) at org.apache.xerces.impl.xs.traversers.XSDElementTraverser.traverseLocal(Unknown Source) at org.apache.xerces.impl.xs.traversers.XSDElementTraverser.traverseLocal(Unknown Source) at org.apache.xerces.impl.xs.traversers.XSDAbstractParticleTraverser.traverseSeqChoice(Unknown Source) at org.apache.xerces.impl.xs.traversers.XSDAbstractParticleTraverser.traverseChoice(Unknown Source) at org.apache.xerces.impl.xs.traversers.XSDComplexTypeTraverser.processComplexContent(Unknown Source) at org.apache.xerces.impl.xs.traversers.XSDComplexTypeTraverser.traverseComplexTypeDecl(Unknown Source) at org.apache.xerces.impl.xs.traversers.XSDComplexTypeTraverser.traverseLocal(Unknown Source) at org.apache.xerces.impl.xs.traversers.XSDElementTraverser.traverseNamedElement(Unknown Source) at org.apache.xerces.impl.xs.traversers.XSDElementTraverser.traverseLocal(Unknown Source) at org.apache.xerces.impl.xs.traversers.XSDHandler.traverseLocalElements(Unknown Source) at org.apache.xerces.impl.xs.traversers.XSDHandler.parseSchema(Unknown Source) at org.apache.xerces.impl.xs.XMLSchemaLoader.loadSchema(Unknown Source) at org.apache.xerces.impl.xs.XMLSchemaLoader.loadGrammar(Unknown Source) at org.apache.xerces.impl.xs.XMLSchemaLoader.loadGrammar(Unknown Source) at org.apache.xerces.jaxp.validation.XMLSchemaFactory.newSchema(Unknown Source) at com.work.test.generateErrorLog(SchemaValidator.java:197)

what is the problem in code? Is their is any other way to validate against multiple schema?