DBDesignerXMLの文字コード
id:shmorimo001さんからの質問を受けて
ソースコードをダウンロードして調べてみましたが
中でこんなことをしているみたいです。
EERModel.pas
MainDM.pas
'Comments="'+DMMain.EncodeText4XML(ModelComments)+'" '
function TDMMain.EncodeText4XML(s: string): string;
var i,j,k: integer;
rs : String; //our result string
newTxt :String;
replace : Boolean;
begin
//theoretically each char could be of ord() > 126
SetLength(rs, Length(s)* 4);//Encode special Chars
i:=1; //the index of the source-string
j:=1; //the index of the result-stringwhile (i<= Length(s)) do
begin
Replace := true;if(Ord(s[i])>126)then newTxt:= '\'+IntToStr(Ord(s[i]))
else if (s[i] = '\') then newTxt := '\\'
else if (s[i] = #13) then newTxt := ''
else if (s[i] = #10) then newTxt := '\n'
else if (s[i] = '"') then newTxt := '\A'
else if (s[i] = '''') then newTxt := '\a'
else if (s[i] = '&') then newTxt := '\+'
else if (s[i] = '<') then newTxt := '\k'
else if (s[i] = '>') then newTxt := '\g'
else { nothing should be replaced }
begin
rs[j] := s[i];
inc(j);
Replace := false;
end;
if (Replace) then //we have to replace s[i] with newTxt
begin
k:= 1;
while (k <= length(newTxt) ) do
begin
rs[j] := newTxt[k];
inc(j);
inc(k);
end;
end;inc(i);
end;EncodeText4XML:=AnsiLeftStr(rs,j-1);
end;