我们有两个架构(XSD)文件,一个文件包含另一个。当我们加载架构文件以验证XML文件时,它没有正确加载到Web应用程序中。它为包含的模式文件元素引发错误。
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包含a.xsd文件。但是,当我们在main方法中运行它时,相同的代码也可以正常工作。
有人可以提出解决此问题的建议吗?
我们可以使用org.w3c.dom.ls包中的LSResourceResolver做到这一点。使用Java和带有include的XSD验证XML文件时出现问题
Web基础应用程序中是否可以使用javax做到这一点?
错误:
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)
LSResourceResolver是一个很好的工具,它使用了整个xml解析基础结构。
简单的破解将是:
还是容易得多
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句