[英]Referencing a XSD schema within jar file
我有兩個模式文件,一個從另一個導入。 在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 <xsd:schema>.
謝謝
如果Liso.xsd
是進口LisoXml.xsd
,那么它僅僅是足以定義Liso.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,您可能會遇到此問題 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.