Java 7 http ://www. oracle.com/xml/jaxp/properties/xmlSecurityPropertyManager

标签 java xml xsd

在 Java 6 中解析 XSD 的旧代码在 Java 7 中失败。原因归结为属性 http://www.oracle.com/xml/jaxp/properties/xmlSecurityPropertyManager未设置,这会导致 NullPointerException。代码:

System.setProperty(DOMImplementationRegistry.PROPERTY, "com.sun.org.apache.xerces.internal.dom.DOMXSImplementationSourceImpl");
    DOMImplementationRegistry registry = newInstance();
    XSImplementation impl = (XSImplementation) registry.getDOMImplementation("XS-Loader");
    XSLoader schemaLoader = impl.createXSLoader(null);

    String url = SchemaParser.class.getResource("/some.xsd").toURI().toString();

    XSModel model = schemaLoader.loadURI(url);

NPE 发生在 loadUri 类 XSDHandler.reset() 中:

    XMLSecurityPropertyManager securityPropertyMgr = (XMLSecurityPropertyManager)
            componentManager.getProperty(XML_SECURITY_PROPERTY_MANAGER);
    //Passing on the setting to the parser
    fSchemaParser.setProperty(XML_SECURITY_PROPERTY_MANAGER, securityPropertyMgr);;

securityPropertyMgr,setProperty() 抛出 NPE。我怎样才能解决这个问题?

最佳答案

他们使用 == 比较。我不得不使用常量:

((XSLoaderImpl)loader).setParameter(
     com.sun.org.apache.xerces.internal.impl.Constants.XML_SECURITY_PROPERTY_MANAGER, 
     new XMLSecurityPropertyManager());

参见:http://osdir.com/ml/core-libs-dev/2013-08/msg00260.html但它是针对 JDK 8 的,我希望我们能在 7 中得到修复,但我没有成功发布它的错误。

关于Java 7 http ://www. oracle.com/xml/jaxp/properties/xmlSecurityPropertyManager,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19201185/

相关文章:

xml - 在 XML 中使用 targetNamespace

java - 使用 Maven 生成 Jaxb 类时包被删除,生成的 Maven 包名称不正确

java - RowNum 行为

java - 线程等到所有线程使用 java 返回输出?

java - 在 Play 框架中导入 astyanax 库

python - XML 解析 - ^H 字符/符号?

xml - 使用xslt基于xml标签动态插入查询

c# - 通过 XMLElement 的 InnerText 对 XML 文件进行排序

java - 使用java更改FAB( float 操作按钮)srcCompat

C#:是否应该在调用的方法中关闭/处置 Streams?