我有要求使用一组模式对传入的XML进行一些验证。
所有这些模式共享相同的目标名称空间,但分为不同的.xsd文件。
我的java程序正在将每个xsd文件加载到InputSource []数组中,并将它们传递到SAX解析器(SCHEMA_SOURCE属性)中。
但是,在调用XMLReader.parse方法时,我得到以下堆栈跟踪:
java.lang.IllegalArgumentException:当使用对象数组作为SCHEMA_SOURCE属性的值时,没有两个Schema应该共享同一个targetNamespace。
在org.apache.xerces.impl.xs.XMLSchemaLoader.processJAXPSchemaSource(未知来源)
在org.apache.xerces.impl.xs.XMLSchemaLoader.loadSchema(未知来源)
at org.apache.xerces.impl.xs.XMLSchemaValidator.findSchemaGrammar(Unknown Source)
at org.apache.xerces.impl.xs.XMLSchemaValidator.handleStartElement(Unknown Source)
在org.apache.xerces.impl.xs.XMLSchemaValidator.startElement(未知来源)
在org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(未知来源)
at org.apache.xerces.impl.XMLNSDocumentScannerImpl $ NSContentDispatcher.scanRootElementHook(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl $ FragmentContentDispatcher.dispatch(Unknown Source)
在org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(未知来源)
在org.apache.xerces.parsers.XML11Configuration.parse(未知来源)
在org.apache.xerces.parsers.XML11Configuration.parse(未知来源)
在org.apache.xerces.parsers.XMLParser.parse(未知来源)
在org.apache.xerces.parsers.AbstractSAXParser.parse(未知来源)
我需要使用共享命名空间的模式来解析XML。是否有可能做到这一点,并避免上述错误?
任何形式的帮助或建议将不胜感激
谢谢