gpt4 book ai didi

java - Xerces - SchemaFactory 无法识别该功能,但 Validator 可以识别该功能

转载 作者:行者123 更新时间:2023-12-01 05:10:35 25 4
gpt4 key购买 nike

我正在尝试设置 Xerces XML 验证的功能。我很难找到/理解哪些功能对 SchemaFactoryValidator 有效。

我有以下代码:

SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_US_URI);
factory.setFeature("http://xml.org/sax/features/validation", true);

Schema schema = factory.newSchema(mySchemaList);
Validator validator = schema.newValidator;
validator.setFeature("http://xml.org/sax/features/validation", true);

如果我执行上述操作,我会得到:SAXNotRecognizedException:功能“http://xml.org/sax/features/validation

但是,如果我注释掉 SchemaFactorysetFeature,则设置该功能适用​​于 Validator

所以问题:

  1. 为什么我可以在 Validator 上设置该功能,但不能在 SchemaFactory 上设置该功能?
  2. 在哪里可以找到有关哪些功能对 ValidatorSchemaFactory 有效的文档?

仅供引用:我得到的SchemaFactorycom.sun.org.apache.xerces.internal.jaxp.validation.XMLSchemaFactory

编辑

我尝试设置但没有成功的其他一些功能是:

http://xml.org/sax/features/namespaces

http://xml.org/sax/features/namespace-prefixes

最佳答案

来自JavaDoc of setFeature

Set a feature for this SchemaFactory, Schemas created by this factory, and by extension, Validators and ValidatorHandlers created by those Schemas.

Implementors and developers should pay particular attention to how the special Schema object returned by newSchema() is processed. In some cases, for example, when the SchemaFactory and the class actually loading the schema come from different implementations, it may not be possible for SchemaFactory features to be inherited automatically. Developers should make sure that features, such as secure processing, are explicitly set in both places.

如您所见,由于某些限制,某些功能可能无法继承。话虽如此,Xerces 2.7.x version seems to have a bug around this which was fixed from the 2.8.x onwards .

关于java - Xerces - SchemaFactory 无法识别该功能,但 Validator 可以识别该功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12072867/

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