本文介绍了如何提高 Java 中针对 xsd 的大型 xml 验证的速度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试针对 XSD 验证非常 XML (~200MB).需要将近3个小时.我不确定我在这里做错了什么?
I'm trying to validate a very XML (~200MB) against XSD. It's taking almost 3 hours. I'm not sure what am I doing wrong here?
SchemaFactory sf = SchemaFactory.newInstance(W3C_XML_SCHEMA_NS_URI);
Schema schema = sf.newSchema(new File(this.productExtraInfoXsd));
DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
domFactory.setNamespaceAware(true);
DocumentBuilder builder = domFactory.newDocumentBuilder();
Document doc = builder.parse(new File(filePath));
DOMSource domSource = new DOMSource(doc);
DOMResult result = new DOMResult();
Validator validator = schema.newValidator();
validator.validate(domSource, result);
推荐答案
查看 Marco Tedone 关于 XML 解组的这篇文章,参见 此处.根据他你可以看到 Stax
check this article on XML unmarshalling from Marco Tedone see here. Based on his you can see Stax
XMLInputFactory xmlInputFactory = XMLInputFactory.newInstance();
XMLStreamReader xmlStreamReader = xmlInputFactory.createXMLStreamReader(fileInputStream);
Validator validator = schema.newValidator();
validator.validate(new StAXSource(xmlStreamReader));
这篇关于如何提高 Java 中针对 xsd 的大型 xml 验证的速度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!