procedure TMainForm.SaveToXML(aFileName:
string);
var
xmlDoc: IXMLDOMDocument2;
mainNode, subNode, subsubNode: IXMLDOMNode;
curData, curSubData: TData;
rootnode, subrootnode: PVirtualNode;
i, j: integer;
f: TextFile;
begin
DeleteFile(aFileName);
AssignFile(f, aFileName);
Rewrite(f);
writeln(f, '
<?xml version="1.0"?>');
writeln(f, '
<projects>');
writeln(f, '
</projects>');
CloseFile(f);
xmlDoc := CoDOMDocument40.Create();
xmlDoc.load(aFileName);
if XMLDoc.parseError.errorCode <> 0
then begin
ShowMessage('
XML Fehler: ' + #13#10 + XMLDoc.parseError.reason + #13#10
+ '
Source: ' + xmldoc.parseError.srcText);
xmldoc :=
nil;
end;
rootNode := vstProjects.RootNode;
for i:=0
to vstProjects.RootNodeCount - 1
do begin
curData := PData(vstProjects.GetNodeData(rootNode))^;
if not Assigned(@curData)
then break;
mainNode := xmlDoc.createElement('
project');
xmlDoc.documentElement.appendChild(mainNode);
subNode := xmlDoc.createElement('
name');
subNode.text := curData.
Name;
mainNode.appendChild(subNode);
xmlDoc.documentElement.appendChild(mainNode);
subNode := xmlDoc.createElement('
prglanguage');
subNode.text := curData.PrgLanguage;
mainNode.appendChild(subNode);
xmlDoc.documentElement.appendChild(mainNode);
subNode := xmlDoc.createElement('
language');
subNode.text := curData.Language;
mainNode.appendChild(subNode);
xmlDoc.documentElement.appendChild(mainNode);
subNode := xmlDoc.createElement('
projectdir');
subNode.text := curData.ProjectDir;
mainNode.appendChild(subNode);
xmlDoc.documentElement.appendChild(mainNode);
subNode := xmlDoc.createElement('
sourcefiles');
subRootNode := rootNode.LastChild;
for j:=0
to rootNode.ChildCount - 1
do begin
curSubData := PData(vstProjects.GetNodeData(subRootNode))^;
xmlDoc.documentElement.appendChild(mainNode);
subsubNode := xmlDoc.createElement('
name');
subsubNode.text := curSubData.
Name;
subNode.appendChild(subsubNode);
xmlDoc.documentElement.appendChild(mainNode);
subsubNode := xmlDoc.createElement('
prglanguage');
subsubNode.text := curSubData.PrgLanguage;
subNode.appendChild(subsubNode);
xmlDoc.documentElement.appendChild(mainNode);
subsubNode := xmlDoc.createElement('
filename');
subsubNode.text := curSubData.FileName;
subNode.appendChild(subsubNode);
subRootNode := subRootNode.NextSibling;
end;
mainNode.appendChild(subNode);
xmlDoc.save(aFileName);
rootNode := rootNode.NextSibling;
end;
end;