我想知道如何在Xliff文件中添加新的Line / Element / Content。
我将DelphiXe³与TXMLDocument组件一起使用
<xliff version="1.1">
<file original="myfile.ext" datatype="plaintext" Source-language="en-US" target-language="fr-FR">
<body>
<trans-unit id='#1'>
<source>Der Text.</source>
<target>Le texte.</target>
</trans-unit>
<trans-unit id='#2'>
<source>Das Flugzeug</source>
<target>l'avion.</target>
</trans-unit>
<trans-unit id='#3'>
<source>Der Baum.</source>
</trans-unit>
</body>
</file>
</xliff>
我想在<target>l'arbre</target>
<source>
行之后插入<trans-unit id='#3'>
答案 0 :(得分:1)
const
c_target='target';
var
i:integer;
NodeElement,NodeElement2: IXMLNode;
begin
NodeElement:= XML.ChildNodes.FindNode('xliff');
if Assigned(NodeElement) then NodeElement:= NodeElement.ChildNodes.FindNode('file');
if Assigned(NodeElement) then NodeElement:= NodeElement.ChildNodes.FindNode('body');
if Assigned(NodeElement) then
begin
for I := 0 to NodeElement.ChildNodes.Count - 1 do
begin
if NodeElement.ChildNodes[i].Attributes['id']='#3' then
begin
NodeElement2 := NodeElement.ChildNodes[i].ChildNodes.FindNode(c_target);
if not Assigned(NodeElement2) then NodeElement2 := NodeElement.ChildNodes[i].AddChild(c_target);
NodeElement2.NodeValue := 'l''arbre';
//XML.SaveToFile('C:\temp\test.xml');
end;
end;
end;
end;