代码如下,请帮一下
procedure XML2Tree(tree : TTreeView;
XMLDoc : TXMLDocument);
var
jNode : IXMLNode;
procedure ProcessNode(Node : IXMLNode;
tn : TTreeNode);
var
cNode : IXMLNode;
begin
if Node = nil then
Exit;
tn := tree.Items.AddChild(tn, Node.Attributes['text']);
tn.ImageIndex := Integer(Node.Attributes['imageIndex']);
tn.StateIndex := Integer(Node.Attributes['stateIndex']);
cNode := Node.ChildNodes.First;
while cNode <> nildo
begin
ProcessNode(cNode, tn);
cNode := cNode.NextSibling;
end;
end;
(*ProcessNode*)
begin
tree.Items.Clear;
XMLDoc.FileName := ChangeFileExt(ParamStr(0),'.XML');
XMLDoc.Active := True;
if XMLDoc.ChildNodes.First = nil then
begin
ShowMessage('nil');
Exit;
end;
jNode := XMLDoc.DocumentElement.ChildNodes.First;
while jNode <> nildo
begin
ProcessNode(jNode,nil);
jNode := jNode.NextSibling;
end;
XMLDoc.Active := False;
end;