我有以下代码:
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);
}
}
对我的 XSD 文件执行该行似乎schemaFactory.newSchema(streamSources);
需要很长时间(30 秒)。
在对这个 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"
or maxOccurs="unbounded"
,速度非常快。
有人可以告诉我使用有什么问题maxOccurs="10000"
吗?