Einzelnen Beitrag anzeigen

CalganX

Registriert seit: 21. Jul 2002
Ort: Bonn
5.403 Beiträge
 
Turbo Delphi für Win32
 
#16

Re: TVirtualStringTree -> XML

  Alt 7. Jul 2003, 16:03
*ächz* Gott sei Dank gibt es sowas, wie MSN Messenger. Mit philwo's Hilfe habe ich es dann doch hinbekommen.
so sieht das ganze jetzt aus:
Code:
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);

  xmlDoc.setProperty('NewParser', true);


  if XMLDoc.parseError.errorCode <> 0 then begin
    ShowMessage('XML Fehler: ' + #13#10 + XMLDoc.parseError.reason + #13#10
                + 'Source: ' + xmldoc.parseError.srcText);
    xmldoc := nil;
  end;

[color=#ff0000] rootNode := vstProjects.RootNode.FirstChild; [/color]

  for i:=0 to vstProjects.RootNodeCount - 1 do begin
    if rootNode = nil then Exit;
    curData := PData(vstProjects.GetNodeData(rootNode))^;
    if not Assigned(@curData)then ShowMessage('Alert');
    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');
[color=#ff0000]   subRootNode := rootNode.FirstChild;[/color]
    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;
Chris
  Mit Zitat antworten Zitat