我的要求是删除xml文件中的几个xml节点(文件大小约为200 MB)并保存它。我正在使用DOMParser并能够读取文件并删除节点并写入xml文件,但是在编写时到xml文件中,在线程“主”中获取异常java.lang.OutOfMemoryError:Java堆空间。
我在transformer.transform(源,结果)处出现内存不足错误; 谁能帮助我解决以上错误。 java中解析xml文件的最佳解析器是什么? DOMParser是否适合解析大型XML文件?请提出建议。这很紧急。谢谢
DocumentBuilder docBuilder = null;
File inputFile = new File("C:/Users/dvoota.ORADEV/Desktop/5277603.xml");
try{
DocumentBuilderFactory docBuilderFactory =
DocumentBuilderFactory.newInstance();
// docBuilderFactory.setExpandEntityReferences(false);
// docBuilderFactory.setValidating(true);
// docBuilderFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
docBuilder = docBuilderFactory.newDocumentBuilder();
Document doc= docBuilder.parse(inputFile);
Element table = doc.getDocumentElement();
Node nlist= table.getElementsByTagName("G_JRNLSOURCE_ROWSET").item(0);
table.removeChild(nlist);
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
DOMSource source = new DOMSource(doc);
StreamResult result = new StreamResult(new File("C:/Users/dvoota.ORADEV/Desktop/5277603.xml"));
transformer.transform(source, result);