var
i:Integer;
s,strDir:string;
MDoc:TXMLDocument;
aNode:IXMLNode;
begin
strDir := GetCurrentDir;
MDoc:=TXMLDocument.Create(nil);
MDoc.XML.Clear;
MDoc.Active := true; //激活XMLDoc,自动初始化空的XML文档
MDoc.Version := '1.0';
MDoc.Encoding := 'GB2312'; //设置字符集
try //If not(treeview.Items=nil) Then
// exit;
//For i:=0 To Treeview.Items.Count-1 Do
//begin
//加入根结点
aNode:=MDoc.AddChild('DSTreeRoot');
//加入子结点
aNode:=aNode.AddChild('DSTree');
//设置接点属性
aNode.setAttribute('text', '22');
aNode.SetAttribute('open', 'Ture/False');
aNode.SetAttribute('href','http://');
aNode.SetAttribute('target','box');
aNode.SetAttribute('treeId','16');
//设置结点内容
aNode.Text := '结点内容';
finally
MDoc.SaveToFile(strDir+'\Tree.xml'); //把组织好的XML文档存于Tree.xml文件中
MDoc.Active := False; //钝化(关闭)XMLDoc
end;
end;MDoc.SaveToFile(strDir+'\Tree.xml');这一段报错
i:Integer;
s,strDir:string;
MDoc:TXMLDocument;
aNode:IXMLNode;
begin
strDir := GetCurrentDir;
MDoc:=TXMLDocument.Create(nil);
MDoc.XML.Clear;
MDoc.Active := true; //激活XMLDoc,自动初始化空的XML文档
MDoc.Version := '1.0';
MDoc.Encoding := 'GB2312'; //设置字符集
try //If not(treeview.Items=nil) Then
// exit;
//For i:=0 To Treeview.Items.Count-1 Do
//begin
//加入根结点
aNode:=MDoc.AddChild('DSTreeRoot');
//加入子结点
aNode:=aNode.AddChild('DSTree');
//设置接点属性
aNode.setAttribute('text', '22');
aNode.SetAttribute('open', 'Ture/False');
aNode.SetAttribute('href','http://');
aNode.SetAttribute('target','box');
aNode.SetAttribute('treeId','16');
//设置结点内容
aNode.Text := '结点内容';
finally
MDoc.SaveToFile(strDir+'\Tree.xml'); //把组织好的XML文档存于Tree.xml文件中
MDoc.Active := False; //钝化(关闭)XMLDoc
end;
end;MDoc.SaveToFile(strDir+'\Tree.xml');这一段报错
or MDoc:=TXMLDocument.Create(Application);试试。