G'day,
I have XML in two formats. The first is a string, the second is a TStringList. In each case I would like to tidy the XML before exporting it. Indented tags.
I've established the following does the trick...
uses
DOM, XMLRead, XMLWrite;
var
sNewFilename: String;
oDOM : TXMLDocument;
dt : TDateTime;
begin
sNewFilename := ExcludeTrailingBackslash(ExtractFileDir(FileNameEdit1.FileName)) + '\New.xml';
oDOM := TXMLDocument.Create;
Try
dt := Now;
ReadXMLFile(oDOM, FileNameEdit1.FileName);
Memo1.Lines.Add('Reading Time');
Memo1.Lines.Add(Format('%.1f msec', [24*60*60*1000*(Now-dt)]));
dt:= Now;
WriteXMLFile(oDOM, sNewFilename);
Memo1.Lines.Add('Writing Time');
Memo1.Lines.Add(Format('%.1f msec', [24*60*60*1000*(Now-dt)]));
finally
oDom.Free;
end;
end;
My problem is the above is slow. 30 millisec to read the file. 7 millisec to write it.
I'm only tidying the XML to scratch an pedantic itch. No user will ever see the XML, so who cares what it looks like? Answer: I do :-( But I'm not willing to pay a nearly 40 millisec cost :-(
Anyone know of a fast routine somewhere that will tidy XML?