使用GpFluentXML:
var
root : IXMLNode;
rowID: integer;
xml : IGpFluentXmlBuilder;
begin
xml := CreateFluentXml
.AddChild('root')
['ver', '']
['file', '']
.Anchor(root);
for rowID := 1 to 10 do begin
xml
.Jump(root)
.AddChild('row')
.AddChild('id', rowID)
.AddSibling('name', '')
.AddSibling('surname', '')
.AddSibling('time', '')
.AddSibling('old', '')
.AddSibling('subject', '');
end;
XMLSaveToFile(xml.Xml, 'filename', ofIndent);
end;
使用 OmniXMLUtils(OmniXML 发行版的一部分):
var
row : IXMLNode;
rowID: integer;
xml : IXMLDocument;
begin
xml := ConstructXMLDocument('root');
SetNodeAttr(xml.DocumentElement, 'ver', '');
SetNodeAttr(xml.DocumentElement, 'file', '');
for rowID := 1 to 10 do begin
row := AppendNode(xml, 'row');
SetNodeTextInt(row, 'id', rowID);
SetNodeText(row, 'name', '');
SetNodeText(row, 'surname', '');
SetNodeText(row, 'time', '');
SetNodeText(row, 'old', '');
SetNodeText(row, 'subject', '');
end;
XMLSaveToFile(xml, 'filename', ofIndent);
end;
至于排序,您不对 XML 进行排序;在将数据添加到文档之前对其进行排序。