用于解析 XSD 模式文件的 Java API

2022-01-09 00:00:00 xml xsd java

是否有用于解析 XSD 模式文件的 Java API?

Is there a Java API to parse an XSD schema file?

我找到了XSOM,但它似乎不再维护了.

I found XSOM, but it doesn't seem to be maintained anymore.

推荐答案

使用标准 JDK 6:

Using standard JDK 6:

System.setProperty(DOMImplementationRegistry.PROPERTY, "com.sun.org.apache.xerces.internal.dom.DOMXSImplementationSourceImpl");
DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance(); 
com.sun.org.apache.xerces.internal.impl.xs.XSImplementationImpl impl = (XSImplementationImpl) registry.getDOMImplementation("XS-Loader");
XSLoader schemaLoader = impl.createXSLoader(null);
XSModel model = schemaLoader.loadURI("src/test/resources/my.xsd");

相关文章