unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,msxml,XMLIntf,XMLDoc;
type
TForm1 = class(TForm)
Button1: TButton;
Memo1: TMemo;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
xmlDoc:IXMLDocument;
trsnode, tmpnode, tmpnode2:IXMLNode;
trnode: ixmlnodelist;
m1,m2,l1,l2:string;
fm, fl: boolean;
i:integer;
begin
xmlDoc := TXMLDocument.Create(nil);
xmldoc.LoadFromFile('E:\bfcec\trans\ap\all.utf8.xml');
xmldoc.Encoding:='utf-8';
trsnode:=xmldoc.ChildNodes.FindNode('TranslationElements');
trnode:=trsnode.ChildNodes;
for i:= 1 to trnode.Count do
begin
m1:='';
l1:='';
m2:='';
l2:='';
fm:=true;
fl:=true;
try
tmpnode:=trnode.Nodes[i-1].ChildNodes.FindNode('SourceLiterals');
if tmpnode<>nil then tmpnode:=tmpnode.ChildNodes.FindNode('LiteralSet');
if tmpnode<>nil then tmpnode:=tmpnode.ChildNodes.FindNode('MediumDescription');
if tmpnode <> nil then m1:=tmpnode.Text;
except
m1:='';
end;
try
tmpnode:=trnode.Nodes[i-1].ChildNodes.FindNode('TargetLiterals');
if tmpnode<>nil then tmpnode:=tmpnode.ChildNodes.FindNode('LiteralSet');
except
m2:='';
fm:=false;
end;
try
if tmpnode<>nil then tmpnode2:=tmpnode.ChildNodes.FindNode('MediumDescription');
if tmpnode2<>nil then m2:=tmpnode2.Text;
if tmpnode2=nil then tmpnode.AddChild('MediumDescription');
except
end;
m1:=trim(m1);
m2:=trim(m2);
if (m1<>'') and (m2='') and fm then
begin
//if tmpnode = nil then trnode.Nodes[i-1].ChildNodes.FindNode('TargetLiterals').ChildNodes.FindNode('LiteralSet').AddChild('MediumDescription');
trnode.Nodes[i-1].ChildNodes.FindNode('TargetLiterals').ChildNodes.FindNode('LiteralSet').ChildNodes.FindNode('MediumDescription').Text:=m1;
end;
try
tmpnode:=trnode.Nodes[i-1].ChildNodes.FindNode('SourceLiterals');
if tmpnode<>nil then tmpnode:=tmpnode.ChildNodes.FindNode('LiteralSet');
except
l1:='';
end;
try
if tmpnode<>nil then tmpnode2:=tmpnode.ChildNodes.FindNode('LongDescription');
if tmpnode2<>nil then l1:=tmpnode2.Text;
if tmpnode2=nil then tmpnode.AddChild('LongDescription');
except
end;
try
tmpnode:=trnode.Nodes[i-1].ChildNodes.FindNode('TargetLiterals');
if tmpnode<>nil then tmpnode:=tmpnode.ChildNodes.FindNode('LiteralSet');
if tmpnode<>nil then tmpnode:=tmpnode.ChildNodes.FindNode('LongDescription');
if tmpnode<>nil then l2:=tmpnode.Text;
except
l2:='';
fl:=false;
end;
l1:=trim(l1);
l2:=trim(l2);
if (l1<>'') and (l2='') and fl then
begin
//if tmpnode=nil then trnode.Nodes[i-1].ChildNodes.FindNode('TargetLiterals').ChildNodes.FindNode('LiteralSet').AddChild('LongDescription');
trnode.Nodes[i-1].ChildNodes.FindNode('TargetLiterals').ChildNodes.FindNode('LiteralSet').ChildNodes.FindNode('LongDescription').Text:=l1;
end;
end;
xmldoc.SaveToFile('E:\bfcec\trans\ap\all.out.utf8.xml');
xmldoc:=nil;
showmessage('done');
end;
end.