gpt4 book ai didi

java - 为什么在设置 isSupportingExternalEntities 时出现 SAXNotRecognizedException?

转载 作者:行者123 更新时间:2023-12-04 10:34:02 27 4
gpt4 key购买 nike

我在尝试在 Java 8 中设置“isSupportingExternalEntities”的属性时收到 SAXNotRecognizedException

final SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
sf.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, Boolean.FALSE);

异常(exception):

org.xml.sax.SAXNotRecognizedException:无法识别属性“javax.xml.stream.isSupportingExternalEntities”。

最佳答案

我猜你对 SchemeFactory 使用了错误的属性。根据 OWASP docs你应该使用以下代码

SchemaFactory factory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
factory.setProperty(XMLConstants.ACCESS_EXTERNAL_DTD, "");
factory.setProperty(XMLConstants.ACCESS_EXTERNAL_SCHEMA, "");
Schema schema = factory.newSchema(Source);

关于java - 为什么在设置 isSupportingExternalEntities 时出现 SAXNotRecognizedException?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60274507/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com