我对您的问题不是特别熟悉,但是我从ProgramCreek找到了这个有用的代码段,该代码段演示了如何从LSInput对象(上面列出的第一个方法)中获取XSModel.也可以从输入流中加载XML模式.我稍微修改了代码以达到以下目的:
private LSInput getLSInput(InputStream is) throws InstantiationException,
IllegalAccessException, ClassNotFoundException {
final DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();
final DOMImplementationLS impl = (DOMImplementationLS)registry.getDOMImplementation("LS");
LSInput domInput = impl.createLSInput();
domInput.setByteStream(is);
return domInput;
}
用法:
// obtain your file through some means
File file;
LSInput ls = null;
try {
InputStream is = new FileInputStream(file);
// obtain an LSInput object
LSInput ls = getLSInput(is);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
if (ls != null) {
XMLSchemaLoader xsLoader = new XMLSchemaLoader();
XSModel xsModel = xsLoader.load(ls);
// now use your XSModel object here ...
}