gpt4 book ai didi

java - XML 模式创建需要很长时间

转载 作者:数据小太阳 更新时间:2023-10-29 02:06:32 25 4
gpt4 key购买 nike

我有以下代码:

public XsdValidator(Resource... xsds) {
Preconditions.checkArgument(xsds != null);
try {
this.xsds = ImmutableList.copyOf(xsds);
SchemaFactory schemaFactory = SchemaFactory.newInstance(W3C_XML_SCHEMA_NS_URI);
LOGGER.debug("Schema factory created: {}",schemaFactory);
StreamSource[] streamSources = streamSourcesOf(xsds);
LOGGER.debug("StreamSource[] created: {}",streamSources);
Schema schema = schemaFactory.newSchema(streamSources);
LOGGER.debug("Schema created: {}",schema);
validator = schema.newValidator();
LOGGER.debug("Validator created: {}",validator);
} catch ( Exception e ) {
throw new IllegalArgumentException("Can't build XsdValidator",e);
}
}

schemaFactory.newSchema(streamSources); 行似乎需要很长时间(30 秒)才能对我的 XSD 文件执行。

经过对这个XSD的多次测试,似乎是因为我有:

  <xs:complexType name="entriesType">
<xs:sequence>
<xs:element type="prov:entryType" name="entry" minOccurs="0" maxOccurs="10000" />
</xs:sequence>
</xs:complexType>

问题是 maxOccurs="10000"

使用 maxOccurs="1"maxOccurs="unbounded",速度非常快。

有人能告诉我使用 maxOccurs="10000" 有什么问题吗?

最佳答案

根据我的个人经验,让粒子受某些人认为“不合理”的高值限制是导致性能问题的原因(this link 来 self 的浏览器的最爱)。

根本原因似乎是内存分配(由 maxOccurs 值指示的效果)。

此外,我还记得一个文档项目,它说明了一个阈值,如果超出该阈值,出于所有意图和目的,解析器实际上会将 maxOccurs 视为无界,无论 XSD 说什么(我会重新访问这篇文章,如果我找到它)。

关于java - XML 模式创建需要很长时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19544671/

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