为什么设置isSupportingExternalEntities时会出现SAXNotRecognizedException?

问题描述 投票:0回答:1

我在尝试在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'。

[我在尝试在Java 8最终SchemaFactory sf = SchemaFactory.newInstance(XMLConstants ....]中设置'isSupportingExternalEntities'的属性时遇到了SAXNotRecognizedException,

我想您为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 xml-parsing
1个回答
0
投票
© www.soinside.com 2019 - 2024. All rights reserved.