1
我想从创造一个txt文件,该XML文件创建XML数据...从txt文件
我这样做 代码:
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,但是什么...
谢谢...
您正在从文本文件读取一行文本到一个名为'text'的变量,但是您会检查名为't2'的非初始化变量中的第一个空白。看起来'r:= pos'和't2:= trim'行的顺序是错误的。 –
另请参阅:Trim(Copy(t2,0,r));对于delphi字符串,0应该是1。 – Despatcher
对不起,我纠正了这个......行现在是正确的顺序.. – azrael11