1

txtファイルからこのxmlファイルを作成したい...

私はこのコードを行います:

 FXml := TNativeXml.CreateName('Root');
 FXml.XmlFormat := xfReadable;
 open the file
 AssignFile(TFile,'user.txt');
 Reset(TFile);
 while not eof(TFile) do 
 begin
    Readln(TFile,text);
    r :=  Pos(' ',text);
    t2 := Trim(Copy(text,1,Length(text)));
    t1 := Trim(Copy(t2,0,r));
    FXml.Root.NodeNew('row');
    FXml.Root.NodeByName('row').WriteAttributeString('user',t2);
    FXml.Root.NodeByName('row').WriteAttributeString('pin',t1);
 end;
   FXml.SaveToFile('new.xml');
 FXml.free;

nodebynameで何か間違っていますが、何が...

ありがとうございました...

4

1 に答える 1

1

テキストファイルに複数の行が含まれている場合は、「row」という名前の複数のノードを作成しています。NodeByNameは、常に指定された名前の最初のノードを返します。

NodeNewの結果をTXmlNode型のローカル変数に格納し、それを使用して属性を設定する必要があります。

var
  node: TXmlNode
...
node := FXml.Root.NodeNew('row');
node.WriteAttributeString('user',t2);
node.WriteAttributeString('pin',t1);
于 2012-10-04T07:36:39.130 に答える