编辑:通过从build.gradle中删除xercesImpl jar来解决。
我正在尝试在SAXParserFactory
实例上设置useCatalog功能。在测试中,我回来了
SAXNotRecognizedException: Feature 'http://javax.xml.XMLConstants/feature/useCatalog' is not recognized.
设置SAXParserFactory
的useCatalog功能的正确方法是什么?
我还尝试在CATALOG_FILE
上设置SAXParser
属性,但是测试返回
SAXNotRecognizedException: Property 'javax.xml.catalog.files' is not recognized.
在SAXParser
上设置目录属性的正确方法是什么?
我的示例代码遵循为XMLConstants.USE_CATALOG
提供的JavaDoc示例。
private static final String CATALOG_FILE = CatalogFeatures.Feature.FILES.getPropertyName();
private static final String CATALOG_PREFER = CatalogFeatures.Feature.PREFER.getPropertyName();
SAXParserFactory spf = SAXParserFactory.newInstance();
spf.setNamespaceAware(true);
spf.setXIncludeAware(true);
spf.setFeature(XMLConstants.USE_CATALOG, true);
SAXParser parser = spf.newSAXParser();
if (catalogURIs.size() > 0) {
List<URI> catalogUriList = new ArrayList<>();
for (String uriString : catalogURIs) {
catalogUriList.add(URI.create(uriString));
}
CatalogResolver resolver =
CatalogManager.catalogResolver(CatalogFeatures.defaults(),
catalogUriList.toArray(new URI[catalogUriList.size()]));
parser.setProperty(CATALOG_FILE, resolver);
parser.setProperty(CATALOG_PREFER, "system");
}