AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Algorithmen, Datenstrukturen und Klassendesign graphml format - Erzeugen von Graphen-files mit Delphi
Thema durchsuchen
Ansicht
Themen-Optionen

graphml format - Erzeugen von Graphen-files mit Delphi

Ein Thema von bernhard_LA · begonnen am 25. Feb 2020 · letzter Beitrag vom 28. Feb 2020
 
bernhard_LA

Registriert seit: 8. Jun 2009
Ort: Bayern
1.138 Beiträge
 
Delphi 11 Alexandria
 
#7

AW: graphml format - Erzeugen von Graphen-files mit Delphi

  Alt 28. Feb 2020, 13:37
ohne Verwendung des XML Databinding sieht meine aktuelle Lösung wie folgt aus:



Delphi-Quellcode:

var
  i: Integer;
  ColorstringList: TStringList;
  LDocument: IXMLDocument;
  LNodeElement, LGRAPHelement , ChildnodeElement, LSubNodeElement, NodeText,
    NodeCData: IXMLNode;
begin

  ///
  ///
  ///
  ColorstringList := TStringList.Create;
  ColorstringList.Add('green');
  ColorstringList.Add('blue');
  ColorstringList.Add('red');
  ColorstringList.Add('white');
  ColorstringList.Add('purple');
  ColorstringList.Add('green');
  ColorstringList.Add('blue');
  ColorstringList.Add('red');
  ColorstringList.Add('white');
  ColorstringList.Add('purple');
  ColorstringList.Add('green');
  ColorstringList.Add('blue');
  ColorstringList.Add('red');
  ColorstringList.Add('white');
  ColorstringList.Add('purple');

  LDocument := TXMLDocument.Create(nil);
  LDocument.Active := True;

  { Define document content. }
  LDocument.DocumentElement := LDocument.CreateNode('graphml', ntElement, '');
  LDocument.DocumentElement.Attributes['xmlns'] :=
    'http://graphml.graphdrawing.org/xmlns';
  LDocument.DocumentElement.Attributes['xmlns:xsi'] :=
    'http://www.w3.org/2001/XMLSchema-instance';

  ///
  /// <key id="d0" for="node" attr.name="color" attr.type="string"> <default>yellow</default>
  /// </key> <key id="d1" for="edge" attr.name="weight" attr.type="double"/>
  ///

  LNodeElement := LDocument.DocumentElement.AddChild('key', -1);
  LNodeElement.Attributes['id'] := 'key' + IntToStr(1);
  LNodeElement.Attributes['for'] := 'node';
  LNodeElement.Attributes['attr.name'] := 'color';
  LNodeElement.Attributes['attr.type'] := 'string';

  LNodeElement := LDocument.DocumentElement.AddChild('key', -1);
  LNodeElement.Attributes['id'] := 'key' + IntToStr(2);
  LNodeElement.Attributes['for'] := 'edge';
  LNodeElement.Attributes['attr.name'] := 'weight';
  LNodeElement.Attributes['attr.type'] := 'double';

  LGRAPHelement := LDocument.DocumentElement.AddChild('graph', -1);
  LGRAPHelement.Attributes['id'] := 'GRAPH';
  LGRAPHelement.Attributes['edgedefault'] := 'undirected';



  for i := 1 to 10 do
  begin
    LSubNodeElement := LGRAPHelement.AddChild('node', -1);
    LSubNodeElement.Attributes['id'] := 'N' + IntToStr(i);

    /// <data key="d0">green</data>
    ChildnodeElement := LSubNodeElement.AddChild('data');
    ChildnodeElement.Attributes['key']:='key1';
    ChildnodeElement.Text := ColorstringList[i];

  end;

  for i := 1 to 9 do
  begin
    LSubNodeElement := LGRAPHelement.AddChild('edge', -1);
    LSubNodeElement.Attributes['id'] := 'E' + IntToStr(i);
    LSubNodeElement.Attributes['source'] := 'N' + IntToStr(i);
    LSubNodeElement.Attributes['target'] := 'N' + IntToStr(i + 1);

    // <data key="d0">green</data>
    ChildnodeElement := LSubNodeElement.AddChild('data');
    ChildnodeElement.Attributes['key']:='key2';
    ChildnodeElement.Text := IntToStr(Random(5)+1);

  end;

  LSubNodeElement := LGRAPHelement.AddChild('edge', -1);
  LSubNodeElement.Attributes['id'] := 'E' + IntToStr(10);
  LSubNodeElement.Attributes['source'] := 'N' + IntToStr(10);
  LSubNodeElement.Attributes['target'] := 'N' + IntToStr(1);
  // <data key="d0">green</data>
  ChildnodeElement := LSubNodeElement.AddChild('data');
  ChildnodeElement.Attributes['key']:='key2';
  ChildnodeElement.Text := '1';



  LDocument.SaveToFile('e:\testxmlgraph.graphml');

  LDocument.SaveToFile('e:\testxmlgraph1.txt');

  LDocument.SaveToFile('e:\testxmlgraph2.xml');

  redt1.Lines.LoadFromFile('e:\testxmlgraph1.txt');

end;

Geändert von bernhard_LA (28. Feb 2020 um 15:28 Uhr)
  Mit Zitat antworten Zitat
 


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 04:23 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz