在jar文件中引用XSD架构

我有两个模式文件,一个从另一个导入。 在Eclipse模式中执行代码时,但是找不到jar模式文件中的代码

这是代码

SAXParserFactory factory = SAXParserFactory.newInstance(); factory.setNamespaceAware(true); factory.setValidating(false); SchemaFactory schemaFactory = SchemaFactory .newInstance("http://www.w3.org/2001/XMLSchema"); try { factory.setSchema(schemaFactory.newSchema(new Source[] { new StreamSource(getClass().getResource("Liso.xsd") .getFile()), new StreamSource(getClass().getResource("LisoXml.xsd") .getFile()) })); this.saxParser = factory.newSAXParser(); } catch (SAXException se) { System.out.println("SCHEMA : " + se.getMessage()); // problem in the XSD itself } 

这是我得到的错误

 SCHEMA : schema_reference.4: Failed to read schema document 'file:/C:/Tools/lib/LisoTools.jar!/com/xerox/liso/xml/Liso.xsd', because 1) could not find the do cument; 2) the document could not be read; 3) the root element of the document is not . 

谢谢

如果Liso.xsd正在导入LisoXml.xsd ,那么将LisoXml.xsd定义到模式工厂就足够了,如下所示。 api足够智能地加载导入/包含的模式。

 SchemaFactory schemaFactory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema") Schema compiledSchema = schemaFactory.newSchema(getClass().getClassLoader().getResource("Liso.xsd")) 

我证实这适用于1.5和1.6。 在1.6上,如果使用DOM,您可能会遇到此问题 。