function ReplaceString(AString: string): string; begin Result := StringReplace(AString, '&', '&', [rfReplaceAll]); Result := StringReplace(Result, '>', '>', [rfReplaceAll]); Result := StringReplace(Result, '<', '<', [rfReplaceAll]); end; function DataSetToXml(ADataSet: TDataSet; Indent: Integer): string; var i: Integer; Indent1, Indent2: string; temp: string; begin Indent1 := Format('%*s', [Indent * 2, ' ']); Indent2 := Indent1 + ' '; Result := EmptyStr; ADataSet.First; while not ADataSet.Eof do begin Result := Result + Format('%s<%s>'#13#10, [Indent1, 'Record']); for i := 0 to ADataSet.FieldCount - 1 do if ADataSet.Fields[i].DataType in [ftString..ftAutoInc, ftMemo,ftWideString] then begin temp := ReplaceString(ADataSet.Fields[i].AsString) Result := Result + Format('%2:s<%0:s>%1:s</%0:s>'#13#10,[ADataSet.Fields[i].FieldName, temp, Indent2]) end; Result := Result + Format('%s</%s>'#13#10, [Indent1, 'Record']); ADataSet.Next; end; end; function GenerateXml(ADataSet: TDataSet): string; begin Result := Format('<?xml version="1.0" encoding="gb2312"?>'#13#10'<Records>'#13#10'%s</Records>', [DataSetToXml(ADataSet, 1)]); end;