procedure TDemoForm.GatherNodes(doc: IXMLDocument; eParent: IXMLNode; tn: TTreeNodes; nParent: TTreeNode);
var
i: Integer;
eChild: IXMLNode;
nChild: TTreeNode;
begin
if Assigned(nParent)
then nChild := nParent.getFirstChild
else nChild := tn.GetFirstNode;
while Assigned(nChild)
do
begin
eChild := eParent.AddChild(nChild.Text);
GatherNodes(xmlDocument, eChild, tn, nChild);
nChild := nChild.getNextSibling;
end;
end;
procedure TDemoForm.SaveButtonClick(Sender: TObject);
begin
with xmlDocument
do
begin
Active := true;
DocumentElement := CreateElement('
root', '
');
GatherNodes(xmlDocument, DocumentElement, TreeView.Items,
nil);
ShowMessage(
xml.Text);
end;
end;