We have two schema (XSD) files and one file include the other one. When we load the schema file to validate the XML files it is not properly loading in the web-application. It is throwing the error for included schema file elements.
Source[] sources = new StreamSource[2];
Source schemaFile = new StreamSource(Test.class.getClassLoader().getResourceAsStream(“a.xsd”));
sources[0] = schemaFile;
Source schemaFile1 = new StreamSource(Test.class.getClassLoader().getResourceAsStream(“b.xsd”));
sources[1] = schemaFile1;
Schema schema = factory.newSchema(sources);
b.xsd include the a.xsd file. But the same code is working fine when we run it in main method.
Could someone give suggestion to fix this issue?
We can do this with LSResourceResolver in org.w3c.dom.ls package. Problem validating an XML file using Java with an XSD having an include
Is there are any way to do this with javax in web base application?
Error:
org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element 'ns:Request'.
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.XMLErrorReporter.reportError(Unknown Source)
at org.apache.xerces.impl.xs.XMLSchemaValidator.handleStartElement(Unknown Source)
at org.apache.xerces.impl.xs.XMLSchemaValidator.startElement(Unknown Source)
at org.apache.xerces.jaxp.validation.DOMValidatorHelper.beginNode(Unknown Source)
at org.apache.xerces.jaxp.validation.DOMValidatorHelper.validate(Unknown Source)
at org.apache.xerces.jaxp.validation.DOMValidatorHelper.validate(Unknown Source)
at org.apache.xerces.jaxp.validation.ValidatorImpl.validate(Unknown Source)
at javax.xml.validation.Validator.validate(Unknown Source)