Tôi có hai tệp sơ đồ lược đồ được nhập vào từ một lược đồ khác. Khi thực hiện các mã trong schemas Eclipse được tìm thấy nhưng khi thực hiện đoạn code từ file schema jar không được tìm thấyTham chiếu một lược đồ XSD trong tệp jar
đây là mã
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
}
và đây là lỗi tôi nhận được
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>.
Cảm ơn
Tôi nhớ rằng tôi đã có một vấn đề tương tự cách đây hai năm: http://stackoverflow.com/questions/2065868/need-help-with-strange-classgetresource-issue - 'getRessource()' đã làm việc với java 1.4.2 nhưng không phải với java 1.6 ... –
Xác minh rằng jar của bạn có '/ com/xerox/liso/xml/Liso.xsd' được bao gồm và nó trông giống như xsd, cũng vậy :) – rogerdpack