2013-05-08 50 views
0

我想知道如何添加一個新的線/元素/內容到Xliff文件。如何在xliff文件中添加新內容?

林Delphi使用Xe³與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> 

我想在<trans-unit id='#3'>

回答

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; 
<source>行之後插入 <target>l'arbre</target>