Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Algorithmen, Datenstrukturen und Klassendesign (https://www.delphipraxis.net/78-algorithmen-datenstrukturen-und-klassendesign/)
-   -   graphml format - Erzeugen von Graphen-files mit Delphi (https://www.delphipraxis.net/203509-graphml-format-erzeugen-von-graphen-files-mit-delphi.html)

bernhard_LA 25. Feb 2020 12:08

graphml format - Erzeugen von Graphen-files mit Delphi
 
ich möchte unsere Graphen im graphml Format ausgeben http://graphml.graphdrawing.org/prim...ml-primer.html
aktuell bin ich jetzt auf der Suche nach Lösungen/Ansätzen Code Beispielen so etwas in Delphi zu realisieren,
alle Inputs um nicht ganz bei 0 anzufangen -> gerne :-) !!!

TiGü 25. Feb 2020 13:39

AW: graphml format - Erzeugen von Graphen-files mit Delphi
 
Tja, spontan hätte ich gesagt, nehme eine Graphml-Datei, benenne sie nach XML um und importiere per File->New->Other...->Delphi Projects->XML->XML Data Binding, damit der Wizard dir schon mal ein paar IXML...-Typen importiert, aber sowohl in XE5 als auch in Tokyo kommt bei mir "Zugriff verweigert".

Wenn man die XSDs von https://github.com/adolfosbh/cs2as/t...graphml/schema runterlädt und dann per XML Data Binding Wizard die ygraphics.xsd importiert, dann fällt zumindest eine über zweitausend Zeilen lange Pascal-Unit bei raus.
Leider gibt es keine praktischen Load*(), Get*() und New*() Funktionen, weil laut Wizard der Document type nicht definiert ist, aber mit ein bisschen experimentieren bekommst du das sicher hin.
Vielleicht muss man auch alle XSD importieren - zumindest jene, die sich importieren lassen - und dann irgendwie mischen.

bernhard_LA 25. Feb 2020 15:52

AW: graphml format - Erzeugen von Graphen-files mit Delphi
 
ich habe mal eine von unseren graphml Dateien aufgewählt.

Delphi-Quellcode:
<?xml version="1.0" encoding="UTF-8"?>
<graphml xmlns="http://graphml.graphdrawing.org/xmlns"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://graphml.graphdrawing.org/xmlns http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd">


<key id="key0" for="edge" attr.name="Edge Label" attr.type="string" />
der XML Data binding Wizard liefert mir folgende Fehlermeldung mit unserer Datei, "no bindable datatypes found" or selected .....
was mache ich hier falsch ?

TiGü 26. Feb 2020 12:12

AW: graphml format - Erzeugen von Graphen-files mit Delphi
 
Ja, das meinte ich in meinen ersten Absatz. Die GraphML/XML-Dateien zu importieren läuft nicht.
Importiere mal die XSD-Dateien, damit hat man zumindest das Gröbste erschlagen.

TiGü 26. Feb 2020 12:37

AW: graphml format - Erzeugen von Graphen-files mit Delphi
 
Ansonsten kannste natürlich auch alles per Hand machen, siehe TfrmMain.ExportToGraphML in hier:
https://github.com/norgepaul/DUDS/bl....Form.Main.pas

bernhard_LA 27. Feb 2020 07:37

AW: graphml format - Erzeugen von Graphen-files mit Delphi
 
ich habe einen neuen Thread zum Thema XML databinding Wizard gestartet : https://www.delphipraxis.net/203538-...ml#post1458485
Weitere Fragen speziell für GraphXL files dann hier.... (in einem update)

m

bernhard_LA 28. Feb 2020 13:37

AW: graphml format - Erzeugen von Graphen-files mit Delphi
 
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;


Alle Zeitangaben in WEZ +1. Es ist jetzt 14:23 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz