I'm parsing a very large (108 MB) XML with IXMLDocument and unless I compile into 64-bit I get an Out of Memory error. Checking RAM usage during parsing the app is using up to 2.5 GB of RAM, which seems quite excessive. Am I doing something wrong?
procedure TMyDoc.ReadXML;
Var z: TZipFile;
i: Integer;
mem: TBytes;
begin
z := TZipFile.Create;
z.Open(fFileName, zmRead);
i := z.IndexOf('word/document.xml');
if i > -1 then begin
z.Read(i, mem);
TBytesToString(mem, XMLData);
XMLData := UTF8Decode(XMLData);
end;
z.Free;
end;
procedure TMyDoc.Open(Filename: string);
Var i: Integer;
Data: IXMLNode;
Node: IXMLNode;
SubNode: IXMLNode;
XMLDoc: IXMLDocument;
begin
fFileName := Filename;
ReadXML;
XMLDoc := LoadXMLData(XMLData);
XMLData := '';
Data := XMLDoc.DocumentElement; // w:document
Node := Data.ChildNodes.FindNode('w:body');
for I := 0 to Node.ChildNodes.Count-1 do begin
SubNode := Node.ChildNodes[I];
ParseChildEntities(SubNode);
end;
end;
procedure TMyDoc.ParseChildEntities(node:IXMLNode);
Var i: Integer;
begin
if not Node.HasChildNodes then Exit;
for i := 0 to Node.ChildNodes.Count-1 do begin
// some parsing/processing within the current node
end;
// iterate through all the childnodes
for i := 0 to Node.ChildNodes.Count-1 do
if node.ChildNodes[i].HasChildNodes then ParseChildEntities(node.ChildNodes[i]);
end;