procedure TForm1.XMLtoTree;
var
iNode: IXMLNode;
Data : PTreeData;
TreeData : TTreeDataClass;
procedure ProcessNode(Node: IXMLNode; TreeNode: PVirtualNode);
var
cNode: iXMlNode;
VNode, V2Node : PVirtualNode;
Test :
String;
begin
if Node =
nil then Exit;
TreeNode := VirtualTree.AddChild(
nil);
Data := VirtualTree.GetNodeData(TreeNode);
Data.FCaption := Node.NodeName;
Node := INode.AddChild(Data.FCaption);
if Node.HasChildNodes
then begin
cNode := Node.ChildNodes[0];
VNode := VirtualTree.AddChild(TreeNode,
nil);
Data := VirtualTree.GetNodeData(VNode);
Data.FCaption := cNode.NodeName;
cNode := Node.AddChild(Data.FCaption);
if cNode.HasChildNodes
then
cNode := Node.ChildNodes[0];
V2Node := VirtualTree.AddChild(VNode,
nil);
Data.FCaption := cNode.NodeName;
cNode := Node.AddChild(Data.FCaption);
//Data hinzufügen
//Data -> FCaption = Name der Node
//Data -> FObject -> FBeschreibung = Attribut aus XML
while cNode <>
nil do
begin
ProcessNode(cNode, TreeNode);
cNode := cNode.NextSibling;
end;
end;
procedure TForm1.TreeToXML(aFirstnode: PVirtualNode);
var
ProjektHomeNode : IXMLNode;
tn : PVirtualNode;
iNode : IXMLNode;
Data : PTreeData;
TreeData : TTreeDataClass;
procedure ProcessTreeItem(
tn : PVirtualNode;
iNode : IXMLNode;
Data : PTreeData;
TreeData : TTreeDataClass);
var
cNode : IXMLNode;
begin
if (tn=Nil)
then Exit;
Data := VirtualTree.GetNodeData(tn);
cNode := INode.AddChild(Data.FCaption);
cNode.Attributes['
Beschreibung']:= TreeData.FBeschreibung;
cNode.Attributes['
Startzeit']:= TreeData.FStartzeit;
cNode.Attributes['
Zielzeit'] := TreeData.FZielzeit;
cNode.Attributes['
Status'] := TreeData.FCombo1;
cNode.Attributes['
Priorität']:= TreeData.FCombo2;
tn := tn.FirstChild;
while tn <>
nil do begin
ProcessTreeItem(tn, cNode, Data, TreeData);
tn := tn.NextSibling;
end;
end;
(*ProcessTreeItem*)
begin
ProjektDocument.Active := True;
Data := VirtualTree.GetNodeData(aFirstnode);
tn := aFirstnode;
ProjektHomeNode := ProjektDocument.AddChild('
Projekt');
iNode := ProjektHomeNode.AddChild(Data.FCaption);
tn := VirtualTree.TopNode;
TreeData := Data.FObject;
iNode.Attributes['
Beschreibung']:= TreeData.FBeschreibung;
iNode.Attributes['
Startzeit']:= TreeData.FStartzeit;
iNode.Attributes['
Zielzeit'] := TreeData.FZielzeit;
iNode.Attributes['
Status'] := TreeData.FCombo1;
iNode.Attributes['
Priorität']:= TreeData.FCombo2;
while tn <>
nil do
begin
ProcessTreeItem (tn, iNode, Data, TreeData);
tn := tn.NextSibling;
end;
end;