AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren

Verwendung XML databinding wizard

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

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

Verwendung XML databinding wizard

  Alt 27. Feb 2020, 08:58
ich möchte folgende XML Datei mit Delphi Lesen / schreiben, Quelle : http://graphml.graphdrawing.org/prim...ml-primer.html , die XML files beschreiben Graphen.

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="d0" for="node" attr.name="color" attr.type="string">
    <default>yellow</default>
  </key>
  <key id="d1" for="edge" attr.name="weight" attr.type="double"/>
  <graph id="G" edgedefault="undirected">
    <node id="n0">
      <data key="d0">green</data>
    </node>
    <node id="n1"/>
    <node id="n2">
      <data key="d0">blue</data>
    </node>
    <node id="n3">
      <data key="d0">red</data>
    </node>
    <node id="n4"/>
    ......


    <edge id="e0" source="n0" target="n2">
      <data key="d1">1.0</data>
    </edge>
    <edge id="e1" source="n0" target="n1">
      <data key="d1">1.0</data>
    </edge>
    <edge id="e2" source="n1" target="n3">
      <data key="d1">2.0</data>
    </edge>

    .........
    </edge>
  </graph>
</graphml>


die hier ( https://edn.embarcadero.com/article/34110 ) beschriebenen automatisch erzeugten Klassen, Interfaces via XML Databinding wizard würden mir gefallen, nur leider bekomme ich keinen Delphi Code , meine Schritte

Databinding Wizard starten Menue Databinding Wizard durchlaufen , incl. der Fehlermeldung (siehe die 3 Screen dumps)

Was mache ich falsch ?
Miniaturansicht angehängter Grafiken
xml_databinding.png   xml_databinding2.png   xml_databinding3.png  

Geändert von bernhard_LA (27. Feb 2020 um 13:10 Uhr)
  Mit Zitat antworten Zitat
TiGü

Registriert seit: 6. Apr 2011
Ort: Berlin
3.058 Beiträge
 
Delphi 10.4 Sydney
 
#2

AW: Verwendung XML databinding wizard

  Alt 27. Feb 2020, 12:39
Wie ich schon in den anderen Thread schrieb, kannst du auch XML Schema location Dateien (XSD) importieren.
Für GraphML befindet sich hier (http://graphml.graphdrawing.org/specification.html) unter den Punkt Syntax vier XSD-Dateien und eine DTD-Datei.
Leider gelingt es mir in Delphi Tokyo nur für die graphml-structure.xsd eine graphmlstructure.pas zu erzeugen.
Bei den anderen zeigt er auch "No bindable datatypes found or selected" oder zeigt eine Access Violation für die DTD-Datei. Die kann aber auch ein XML-Plugin in Notepad++ nicht validieren, der bricht auch in der ersten Zeile nach dem Kommentar ab.

Meine Vermutung ist, dass da irgendwelche Spezialsachen drin sind, mit denen der Parser nicht zurecht kommt.

Vielleicht mal schauen, was andere Entwicklungsumgebungen daraus machen?
Ggf. musst du eine DLL in C#/Java/C++ entwickeln und dann in deinen Delphi-Programm einbinden.
  Mit Zitat antworten Zitat
bernhard_LA

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

AW: Verwendung XML databinding wizard

  Alt 27. Feb 2020, 13:50
habe die XML Datei ohne den Verweis auf die graphML schemata files etc. erzeugt

XML also wie folgt :

Delphi-Quellcode:

<?xml version="1.0" ?>
<graphml>
  <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"/>
  <graph id="G" edgedefault="undirected">
    <node id="n0">
      <data key="d0">green</data>
    </node>
    <node id="n1"/>
    <node id="n2">
      <data key="d0">blue</data>
    </node>
    <node id="n3">
      <data key="d0">red</data>
    </node>
    <node id="n4"/>
    <node id="n5">
      <data key="d0">turquoise</data>
    </node>
    <edge id="e0" source="n0" target="n2">
      <data key="d1">1.0</data>
    </edge>
    <edge id="e1" source="n0" target="n1">
      <data key="d1">1.0</data>
    </edge>
    <edge id="e2" source="n1" target="n3">
      <data key="d1">2.0</data>
    </edge>
    <edge id="e3" source="n3" target="n2"/>
    <edge id="e4" source="n2" target="n4"/>
    <edge id="e5" source="n3" target="n5"/>
    <edge id="e6" source="n5" target="n4">
      <data key="d1">1.1</data>
    </edge>
  </graph>
</graphml>


Damit habe ich folgenden Code über den XML Import Wizard erzeugt bekommen :

Delphi-Quellcode:
{***************************************************}
{                                                   }
{                 XML Data Binding                  }
{                                                   }
{         Generated on: 27.02.2020 13:43:22         }
{       Generated from: E:\simple_sampleGraph.xml   }
{   Settings stored in: E:\simple_sampleGraph.xdb   }
{                                                   }
{***************************************************}

unit simple_sampleGraph;

interface

uses Xml.xmldom, Xml.XMLDoc, Xml.XMLIntf;

type

{ Forward Decls }

  IXMLGraphmlType = interface;
  IXMLKeyType = interface;
  IXMLKeyTypeList = interface;
  IXMLGraphType = interface;
  IXMLNodeType = interface;
  IXMLNodeTypeList = interface;
  IXMLDataType = interface;
  IXMLEdgeType = interface;
  IXMLEdgeTypeList = interface;
  IXMLKeyType2 = interface;
  IXMLNodeType2 = interface;
  IXMLEdgeType2 = interface;

{ IXMLGraphmlType }

  IXMLGraphmlType = interface(IXMLNode)
    ['{94475E9D-8262-45F1-94D1-E93C8ADE4C26}']
    { Property Accessors }
    function Get_Key: IXMLKeyTypeList;
    function Get_Graph: IXMLGraphType;
    { Methods & Properties }
    property Key: IXMLKeyTypeList read Get_Key;
    property Graph: IXMLGraphType read Get_Graph;
  end;

{ IXMLKeyType }

  IXMLKeyType = interface(IXMLNode)
    ['{06C7B489-7D67-4C30-9207-C86F696B8DD7}']
    { Property Accessors }
    function Get_Id: UnicodeString;
    function Get_For_: UnicodeString;
    function Get_Attrname: UnicodeString;
    function Get_Attrtype: UnicodeString;
    function Get_Default: UnicodeString;
    procedure Set_Id(Value: UnicodeString);
    procedure Set_For_(Value: UnicodeString);
    procedure Set_Attrname(Value: UnicodeString);
    procedure Set_Attrtype(Value: UnicodeString);
    procedure Set_Default(Value: UnicodeString);
    { Methods & Properties }
    property Id: UnicodeString read Get_Id write Set_Id;
    property For_: UnicodeString read Get_For_ write Set_For_;
    property Attrname: UnicodeString read Get_Attrname write Set_Attrname;
    property Attrtype: UnicodeString read Get_Attrtype write Set_Attrtype;
    property Default: UnicodeString read Get_Default write Set_Default;
  end;

{ IXMLKeyTypeList }

  IXMLKeyTypeList = interface(IXMLNodeCollection)
    ['{C67A169A-6CD5-47F0-B07C-49CD97E26EB5}']
    { Methods & Properties }
    function Add: IXMLKeyType;
    function Insert(const Index: Integer): IXMLKeyType;

    function Get_Item(Index: Integer): IXMLKeyType;
    property Items[Index: Integer]: IXMLKeyType read Get_Item; default;
  end;

{ IXMLGraphType }

  IXMLGraphType = interface(IXMLNode)
    ['{A57FE432-41C2-4B25-8951-678436D3AE65}']
    { Property Accessors }
    function Get_Id: UnicodeString;
    function Get_Edgedefault: UnicodeString;
    function Get_Node: IXMLNodeTypeList;
    function Get_Edge: IXMLEdgeTypeList;
    procedure Set_Id(Value: UnicodeString);
    procedure Set_Edgedefault(Value: UnicodeString);
    { Methods & Properties }
    property Id: UnicodeString read Get_Id write Set_Id;
    property Edgedefault: UnicodeString read Get_Edgedefault write Set_Edgedefault;
    property Node: IXMLNodeTypeList read Get_Node;
    property Edge: IXMLEdgeTypeList read Get_Edge;
  end;

{ IXMLNodeType }

  IXMLNodeType = interface(IXMLNode)
    ['{057FD1C7-A841-4F40-B77D-48D4E0440288}']
    { Property Accessors }
    function Get_Id: UnicodeString;
    function Get_Data: IXMLDataType;
    procedure Set_Id(Value: UnicodeString);
    { Methods & Properties }
    property Id: UnicodeString read Get_Id write Set_Id;
    property Data: IXMLDataType read Get_Data;
  end;

{ IXMLNodeTypeList }

  IXMLNodeTypeList = interface(IXMLNodeCollection)
    ['{47E4A7BE-E168-48A6-9526-21E2EE33995B}']
    { Methods & Properties }
    function Add: IXMLNodeType;
    function Insert(const Index: Integer): IXMLNodeType;

    function Get_Item(Index: Integer): IXMLNodeType;
    property Items[Index: Integer]: IXMLNodeType read Get_Item; default;
  end;

{ IXMLDataType }

  IXMLDataType = interface(IXMLNode)
    ['{31740E70-3070-4628-97B4-85D8BA0F9009}']
    { Property Accessors }
    function Get_Key: UnicodeString;
    procedure Set_Key(Value: UnicodeString);
    { Methods & Properties }
    property Key: UnicodeString read Get_Key write Set_Key;
  end;

{ IXMLEdgeType }

  IXMLEdgeType = interface(IXMLNode)
    ['{FEABD4FD-A137-4A65-A6EB-7F29F6F7CE36}']
    { Property Accessors }
    function Get_Id: UnicodeString;
    function Get_Source: UnicodeString;
    function Get_Target: UnicodeString;
    function Get_Data: IXMLDataType;
    procedure Set_Id(Value: UnicodeString);
    procedure Set_Source(Value: UnicodeString);
    procedure Set_Target(Value: UnicodeString);
    { Methods & Properties }
    property Id: UnicodeString read Get_Id write Set_Id;
    property Source: UnicodeString read Get_Source write Set_Source;
    property Target: UnicodeString read Get_Target write Set_Target;
    property Data: IXMLDataType read Get_Data;
  end;

{ IXMLEdgeTypeList }

  IXMLEdgeTypeList = interface(IXMLNodeCollection)
    ['{431C126D-C2E3-4E2C-9701-EBAEA57B36C4}']
    { Methods & Properties }
    function Add: IXMLEdgeType;
    function Insert(const Index: Integer): IXMLEdgeType;

    function Get_Item(Index: Integer): IXMLEdgeType;
    property Items[Index: Integer]: IXMLEdgeType read Get_Item; default;
  end;

{ IXMLKeyType2 }

  IXMLKeyType2 = interface(IXMLNode)
    ['{9ED8308E-51DE-4A73-B9A1-71D5E80F40E5}']
    { Property Accessors }
    function Get_Id: UnicodeString;
    function Get_For_: UnicodeString;
    function Get_Attrname: UnicodeString;
    function Get_Attrtype: UnicodeString;
    procedure Set_Id(Value: UnicodeString);
    procedure Set_For_(Value: UnicodeString);
    procedure Set_Attrname(Value: UnicodeString);
    procedure Set_Attrtype(Value: UnicodeString);
    { Methods & Properties }
    property Id: UnicodeString read Get_Id write Set_Id;
    property For_: UnicodeString read Get_For_ write Set_For_;
    property Attrname: UnicodeString read Get_Attrname write Set_Attrname;
    property Attrtype: UnicodeString read Get_Attrtype write Set_Attrtype;
  end;

{ IXMLNodeType2 }

  IXMLNodeType2 = interface(IXMLNode)
    ['{17F3BF00-BA6C-4008-BC51-8719279D1001}']
    { Property Accessors }
    function Get_Id: UnicodeString;
    procedure Set_Id(Value: UnicodeString);
    { Methods & Properties }
    property Id: UnicodeString read Get_Id write Set_Id;
  end;

{ IXMLEdgeType2 }

  IXMLEdgeType2 = interface(IXMLNode)
    ['{C73D7761-E7D1-4B30-B7E9-7D8EAAE2492A}']
    { Property Accessors }
    function Get_Id: UnicodeString;
    function Get_Source: UnicodeString;
    function Get_Target: UnicodeString;
    procedure Set_Id(Value: UnicodeString);
    procedure Set_Source(Value: UnicodeString);
    procedure Set_Target(Value: UnicodeString);
    { Methods & Properties }
    property Id: UnicodeString read Get_Id write Set_Id;
    property Source: UnicodeString read Get_Source write Set_Source;
    property Target: UnicodeString read Get_Target write Set_Target;
  end;

{ Forward Decls }

  TXMLGraphmlType = class;
  TXMLKeyType = class;
  TXMLKeyTypeList = class;
  TXMLGraphType = class;
  TXMLNodeType = class;
  TXMLNodeTypeList = class;
  TXMLDataType = class;
  TXMLEdgeType = class;
  TXMLEdgeTypeList = class;
  TXMLKeyType2 = class;
  TXMLNodeType2 = class;
  TXMLEdgeType2 = class;

{ TXMLGraphmlType }

  TXMLGraphmlType = class(TXMLNode, IXMLGraphmlType)
  private
    FKey: IXMLKeyTypeList;
  protected
    { IXMLGraphmlType }
    function Get_Key: IXMLKeyTypeList;
    function Get_Graph: IXMLGraphType;
  public
    procedure AfterConstruction; override;
  end;

{ TXMLKeyType }

  TXMLKeyType = class(TXMLNode, IXMLKeyType)
  protected
    { IXMLKeyType }
    function Get_Id: UnicodeString;
    function Get_For_: UnicodeString;
    function Get_Attrname: UnicodeString;
    function Get_Attrtype: UnicodeString;
    function Get_Default: UnicodeString;
    procedure Set_Id(Value: UnicodeString);
    procedure Set_For_(Value: UnicodeString);
    procedure Set_Attrname(Value: UnicodeString);
    procedure Set_Attrtype(Value: UnicodeString);
    procedure Set_Default(Value: UnicodeString);
  end;

{ TXMLKeyTypeList }

  TXMLKeyTypeList = class(TXMLNodeCollection, IXMLKeyTypeList)
  protected
    { IXMLKeyTypeList }
    function Add: IXMLKeyType;
    function Insert(const Index: Integer): IXMLKeyType;

    function Get_Item(Index: Integer): IXMLKeyType;
  end;

{ TXMLGraphType }

  TXMLGraphType = class(TXMLNode, IXMLGraphType)
  private
    FNode: IXMLNodeTypeList;
    FEdge: IXMLEdgeTypeList;
  protected
    { IXMLGraphType }
    function Get_Id: UnicodeString;
    function Get_Edgedefault: UnicodeString;
    function Get_Node: IXMLNodeTypeList;
    function Get_Edge: IXMLEdgeTypeList;
    procedure Set_Id(Value: UnicodeString);
    procedure Set_Edgedefault(Value: UnicodeString);
  public
    procedure AfterConstruction; override;
  end;

{ TXMLNodeType }

  TXMLNodeType = class(TXMLNode, IXMLNodeType)
  protected
    { IXMLNodeType }
    function Get_Id: UnicodeString;
    function Get_Data: IXMLDataType;
    procedure Set_Id(Value: UnicodeString);
  public
    procedure AfterConstruction; override;
  end;

{ TXMLNodeTypeList }

  TXMLNodeTypeList = class(TXMLNodeCollection, IXMLNodeTypeList)
  protected
    { IXMLNodeTypeList }
    function Add: IXMLNodeType;
    function Insert(const Index: Integer): IXMLNodeType;

    function Get_Item(Index: Integer): IXMLNodeType;
  end;

{ TXMLDataType }

  TXMLDataType = class(TXMLNode, IXMLDataType)
  protected
    { IXMLDataType }
    function Get_Key: UnicodeString;
    procedure Set_Key(Value: UnicodeString);
  end;

{ TXMLEdgeType }

  TXMLEdgeType = class(TXMLNode, IXMLEdgeType)
  protected
    { IXMLEdgeType }
    function Get_Id: UnicodeString;
    function Get_Source: UnicodeString;
    function Get_Target: UnicodeString;
    function Get_Data: IXMLDataType;
    procedure Set_Id(Value: UnicodeString);
    procedure Set_Source(Value: UnicodeString);
    procedure Set_Target(Value: UnicodeString);
  public
    procedure AfterConstruction; override;
  end;

{ TXMLEdgeTypeList }

  TXMLEdgeTypeList = class(TXMLNodeCollection, IXMLEdgeTypeList)
  protected
    { IXMLEdgeTypeList }
    function Add: IXMLEdgeType;
    function Insert(const Index: Integer): IXMLEdgeType;

    function Get_Item(Index: Integer): IXMLEdgeType;
  end;

{ TXMLKeyType2 }

  TXMLKeyType2 = class(TXMLNode, IXMLKeyType2)
  protected
    { IXMLKeyType2 }
    function Get_Id: UnicodeString;
    function Get_For_: UnicodeString;
    function Get_Attrname: UnicodeString;
    function Get_Attrtype: UnicodeString;
    procedure Set_Id(Value: UnicodeString);
    procedure Set_For_(Value: UnicodeString);
    procedure Set_Attrname(Value: UnicodeString);
    procedure Set_Attrtype(Value: UnicodeString);
  end;

{ TXMLNodeType2 }

  TXMLNodeType2 = class(TXMLNode, IXMLNodeType2)
  protected
    { IXMLNodeType2 }
    function Get_Id: UnicodeString;
    procedure Set_Id(Value: UnicodeString);
  end;

{ TXMLEdgeType2 }

  TXMLEdgeType2 = class(TXMLNode, IXMLEdgeType2)
  protected
    { IXMLEdgeType2 }
    function Get_Id: UnicodeString;
    function Get_Source: UnicodeString;
    function Get_Target: UnicodeString;
    procedure Set_Id(Value: UnicodeString);
    procedure Set_Source(Value: UnicodeString);
    procedure Set_Target(Value: UnicodeString);
  end;

implementation

uses Xml.xmlutil;

{ TXMLGraphmlType }

procedure TXMLGraphmlType.AfterConstruction;
begin
  RegisterChildNode('key', TXMLKeyType);
  RegisterChildNode('graph', TXMLGraphType);
  FKey := CreateCollection(TXMLKeyTypeList, IXMLKeyType, 'key') as IXMLKeyTypeList;
  inherited;
end;

function TXMLGraphmlType.Get_Key: IXMLKeyTypeList;
begin
  Result := FKey;
end;

function TXMLGraphmlType.Get_Graph: IXMLGraphType;
begin
  Result := ChildNodes['graph'] as IXMLGraphType;
end;

{ TXMLKeyType }

function TXMLKeyType.Get_Id: UnicodeString;
begin
  Result := AttributeNodes['id'].Text;
end;

procedure TXMLKeyType.Set_Id(Value: UnicodeString);
begin
  SetAttribute('id', Value);
end;

function TXMLKeyType.Get_For_: UnicodeString;
begin
  Result := AttributeNodes['for'].Text;
end;

procedure TXMLKeyType.Set_For_(Value: UnicodeString);
begin
  SetAttribute('for', Value);
end;

function TXMLKeyType.Get_Attrname: UnicodeString;
begin
  Result := AttributeNodes['attr.name'].Text;
end;

procedure TXMLKeyType.Set_Attrname(Value: UnicodeString);
begin
  SetAttribute('attr.name', Value);
end;

function TXMLKeyType.Get_Attrtype: UnicodeString;
begin
  Result := AttributeNodes['attr.type'].Text;
end;

procedure TXMLKeyType.Set_Attrtype(Value: UnicodeString);
begin
  SetAttribute('attr.type', Value);
end;

function TXMLKeyType.Get_Default: UnicodeString;
begin
  Result := ChildNodes['default'].Text;
end;

procedure TXMLKeyType.Set_Default(Value: UnicodeString);
begin
  ChildNodes['default'].NodeValue := Value;
end;

{ TXMLKeyTypeList }

function TXMLKeyTypeList.Add: IXMLKeyType;
begin
  Result := AddItem(-1) as IXMLKeyType;
end;

function TXMLKeyTypeList.Insert(const Index: Integer): IXMLKeyType;
begin
  Result := AddItem(Index) as IXMLKeyType;
end;

function TXMLKeyTypeList.Get_Item(Index: Integer): IXMLKeyType;
begin
  Result := List[Index] as IXMLKeyType;
end;

{ TXMLGraphType }

procedure TXMLGraphType.AfterConstruction;
begin
  RegisterChildNode('node', TXMLNodeType);
  RegisterChildNode('edge', TXMLEdgeType);
  FNode := CreateCollection(TXMLNodeTypeList, IXMLNodeType, 'node') as IXMLNodeTypeList;
  FEdge := CreateCollection(TXMLEdgeTypeList, IXMLEdgeType, 'edge') as IXMLEdgeTypeList;
  inherited;
end;

function TXMLGraphType.Get_Id: UnicodeString;
begin
  Result := AttributeNodes['id'].Text;
end;

procedure TXMLGraphType.Set_Id(Value: UnicodeString);
begin
  SetAttribute('id', Value);
end;

function TXMLGraphType.Get_Edgedefault: UnicodeString;
begin
  Result := AttributeNodes['edgedefault'].Text;
end;

procedure TXMLGraphType.Set_Edgedefault(Value: UnicodeString);
begin
  SetAttribute('edgedefault', Value);
end;

function TXMLGraphType.Get_Node: IXMLNodeTypeList;
begin
  Result := FNode;
end;

function TXMLGraphType.Get_Edge: IXMLEdgeTypeList;
begin
  Result := FEdge;
end;

{ TXMLNodeType }

procedure TXMLNodeType.AfterConstruction;
begin
  RegisterChildNode('data', TXMLDataType);
  inherited;
end;

function TXMLNodeType.Get_Id: UnicodeString;
begin
  Result := AttributeNodes['id'].Text;
end;

procedure TXMLNodeType.Set_Id(Value: UnicodeString);
begin
  SetAttribute('id', Value);
end;

function TXMLNodeType.Get_Data: IXMLDataType;
begin
  Result := ChildNodes['data'] as IXMLDataType;
end;

{ TXMLNodeTypeList }

function TXMLNodeTypeList.Add: IXMLNodeType;
begin
  Result := AddItem(-1) as IXMLNodeType;
end;

function TXMLNodeTypeList.Insert(const Index: Integer): IXMLNodeType;
begin
  Result := AddItem(Index) as IXMLNodeType;
end;

function TXMLNodeTypeList.Get_Item(Index: Integer): IXMLNodeType;
begin
  Result := List[Index] as IXMLNodeType;
end;

{ TXMLDataType }

function TXMLDataType.Get_Key: UnicodeString;
begin
  Result := AttributeNodes['key'].Text;
end;

procedure TXMLDataType.Set_Key(Value: UnicodeString);
begin
  SetAttribute('key', Value);
end;

{ TXMLEdgeType }

procedure TXMLEdgeType.AfterConstruction;
begin
  RegisterChildNode('data', TXMLDataType);
  inherited;
end;

function TXMLEdgeType.Get_Id: UnicodeString;
begin
  Result := AttributeNodes['id'].Text;
end;

procedure TXMLEdgeType.Set_Id(Value: UnicodeString);
begin
  SetAttribute('id', Value);
end;

function TXMLEdgeType.Get_Source: UnicodeString;
begin
  Result := AttributeNodes['source'].Text;
end;

procedure TXMLEdgeType.Set_Source(Value: UnicodeString);
begin
  SetAttribute('source', Value);
end;

function TXMLEdgeType.Get_Target: UnicodeString;
begin
  Result := AttributeNodes['target'].Text;
end;

procedure TXMLEdgeType.Set_Target(Value: UnicodeString);
begin
  SetAttribute('target', Value);
end;

function TXMLEdgeType.Get_Data: IXMLDataType;
begin
  Result := ChildNodes['data'] as IXMLDataType;
end;

{ TXMLEdgeTypeList }

function TXMLEdgeTypeList.Add: IXMLEdgeType;
begin
  Result := AddItem(-1) as IXMLEdgeType;
end;

function TXMLEdgeTypeList.Insert(const Index: Integer): IXMLEdgeType;
begin
  Result := AddItem(Index) as IXMLEdgeType;
end;

function TXMLEdgeTypeList.Get_Item(Index: Integer): IXMLEdgeType;
begin
  Result := List[Index] as IXMLEdgeType;
end;

{ TXMLKeyType2 }

function TXMLKeyType2.Get_Id: UnicodeString;
begin
  Result := AttributeNodes['id'].Text;
end;

procedure TXMLKeyType2.Set_Id(Value: UnicodeString);
begin
  SetAttribute('id', Value);
end;

function TXMLKeyType2.Get_For_: UnicodeString;
begin
  Result := AttributeNodes['for'].Text;
end;

procedure TXMLKeyType2.Set_For_(Value: UnicodeString);
begin
  SetAttribute('for', Value);
end;

function TXMLKeyType2.Get_Attrname: UnicodeString;
begin
  Result := AttributeNodes['attr.name'].Text;
end;

procedure TXMLKeyType2.Set_Attrname(Value: UnicodeString);
begin
  SetAttribute('attr.name', Value);
end;

function TXMLKeyType2.Get_Attrtype: UnicodeString;
begin
  Result := AttributeNodes['attr.type'].Text;
end;

procedure TXMLKeyType2.Set_Attrtype(Value: UnicodeString);
begin
  SetAttribute('attr.type', Value);
end;

{ TXMLNodeType2 }

function TXMLNodeType2.Get_Id: UnicodeString;
begin
  Result := AttributeNodes['id'].Text;
end;

procedure TXMLNodeType2.Set_Id(Value: UnicodeString);
begin
  SetAttribute('id', Value);
end;

{ TXMLEdgeType2 }

function TXMLEdgeType2.Get_Id: UnicodeString;
begin
  Result := AttributeNodes['id'].Text;
end;

procedure TXMLEdgeType2.Set_Id(Value: UnicodeString);
begin
  SetAttribute('id', Value);
end;

function TXMLEdgeType2.Get_Source: UnicodeString;
begin
  Result := AttributeNodes['source'].Text;
end;

procedure TXMLEdgeType2.Set_Source(Value: UnicodeString);
begin
  SetAttribute('source', Value);
end;

function TXMLEdgeType2.Get_Target: UnicodeString;
begin
  Result := AttributeNodes['target'].Text;
end;

procedure TXMLEdgeType2.Set_Target(Value: UnicodeString);
begin
  SetAttribute('target', Value);
end;

end.


bin jetzt auf der Suche nach einer Demo App (code) welche mit diesen Interface Klassen dann auch eine XML Datei liest und schreibt ......
  Mit Zitat antworten Zitat
TiGü

Registriert seit: 6. Apr 2011
Ort: Berlin
3.058 Beiträge
 
Delphi 10.4 Sydney
 
#4

AW: Verwendung XML databinding wizard

  Alt 27. Feb 2020, 14:29
Na ja, wenn man sich auf eine XML stützt, die nur ein paar Sachen drin hat, dann wird der Import nur so halb.

Vergleiche mal den Typen IXMLGraphmltype von deinen Import mit dem Import von der graphml-structure.xsd:

Delphi-Quellcode:
{ IXMLGraphmltype }

  IXMLGraphmltype = interface(IXMLNode)
    ['{8BE8C246-33BF-4052-843A-146FA9F10916}']
    { Property Accessors }
    function Get_Desc: UnicodeString;
    function Get_Key: IXMLKeytypeList;
    function Get_Graph: IXMLGraphtypeList;
    function Get_Data: IXMLDatatypeList;
    procedure Set_Desc(Value: UnicodeString);
    { Methods & Properties }
    property Desc: UnicodeString read Get_Desc write Set_Desc;
    property Key: IXMLKeytypeList read Get_Key;
    property Graph: IXMLGraphtypeList read Get_Graph;
    property Data: IXMLDatatypeList read Get_Data;
  end;
  Mit Zitat antworten Zitat
bernhard_LA

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

AW: Verwendung XML databinding wizard

  Alt 27. Feb 2020, 15:18
werde ich noch machen,
wie bekomme ich jetzt aber einen Parser für meine XML files, hätte gerne ein Referenz Code Beispiel - was ich jetzt am besten mit diesem Auto Created Code mache ....... .
  Mit Zitat antworten Zitat
TiGü

Registriert seit: 6. Apr 2011
Ort: Berlin
3.058 Beiträge
 
Delphi 10.4 Sydney
 
#6

AW: Verwendung XML databinding wizard

  Alt 27. Feb 2020, 15:36
Der Parser ist in Delphi doch schon drin?!
Hattest du noch nie zuvor mit XML in Delphi gearbeitet?

Anbei als Anhang ein Beispiel zum Einlesen deiner Beispiel-XML mit angepasster graphmlstructure.pas, der man jetzt auch XML-Text oder Dateien vorwerfen kann (Getgraphml() und Loadgraphml() Funktionen):

Delphi-Quellcode:
procedure TForm1.FormShow(Sender: TObject);
var
  I, J, L: Integer;
  Graphml: IXMLGraphmltype;
  Graph: IXMLGraphtype;
  Node: IXMLNodetype;
  Data: IXMLDatatype;
  XMLDoc: IXMLDocument;
  GraphMLTreeNode, GraphTreeNode, NodeTreeNode: TTreeNode;
begin
  XMLDoc := LoadXMLData(Memo1.Lines.Text);
  Graphml := Getgraphml(XMLDoc);

  TreeView1.Items.BeginUpdate;
  try
    GraphMLTreeNode := TreeView1.Items.Add(nil, Graphml.NodeName);
    for I := 0 to Graphml.Graph.Count - 1 do
    begin
      Graph := Graphml.Graph.Items[I];
      GraphTreeNode := TreeView1.Items.AddChild(GraphMLTreeNode, Graph.NodeName + ' ' + Graph.Id);
      for J := 0 to Graph.Node.Count - 1 do
      begin
        Node := Graph.Node.Items[J];
        NodeTreeNode := TreeView1.Items.AddChild(GraphTreeNode, Node.NodeName + ' ' + Node.Id);
        for L := 0 to Node.Data.Count - 1 do
        begin
          Data := Node.Data.Items[L];
          TreeView1.Items.AddChild(NodeTreeNode, Data.NodeName + ' ' + Data.Key + ': ' + Data.NodeValue);
        end;
      end;
    end;
  finally
    TreeView1.FullExpand;
    TreeView1.Items.EndUpdate;
  end;
end;
Angehängte Dateien
Dateityp: zip GraphMLTest.zip (9,3 KB, 16x aufgerufen)

Geändert von TiGü (27. Feb 2020 um 15:39 Uhr)
  Mit Zitat antworten Zitat
bernhard_LA

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

AW: Verwendung XML databinding wizard

  Alt 27. Feb 2020, 19:50
Danke für das Beispiel; Anbei der Code zum schreiben einer XML Datei, ein Graph mit 20 Knoten und die Knoten jeweils mit 2 Ecken verbunden :

Delphi-Quellcode:
var
  I, J, L: Integer;
  Graphml: IXMLGraphmltype;
  Graph: IXMLGraphtype;
  Node: IXMLNodetype;
  Data: IXMLDatatype;
  XMLDoc: IXMLDocument;
  Newkey: IXMLKeytype;
  NewNode: IXMLNode;
  NewEdge : IXMLEdgetype;


begin

  /// erzeuge eine einfache graphml / XML Datei

  XMLDoc := TXMLDocument.Create(nil);
  XMLDoc.Active := True;
  Graphml := Newgraphml;

  i:=1;
  Newkey := Graphml.Key.Add;
  Newkey.Id := 'KEY'+IntToStr(I);
  Newkey.For_ := 'egde';

  i:=2;
  Newkey := Graphml.Key.Add;
  Newkey.Id := 'KEY'+IntToStr(I);
  Newkey.For_ := 'node';

  for I := 1 to 20 do
  begin

    NewNode := Graphml.Graph.Add.Node.Add;

    NewNode.Attributes['name'] := 'node' + IntTostr(i);


  end;



  for I := 1 to 19 do
  begin

    NewEdge := Graphml.Graph.Add.Edge.Add;

    NewEdge.Attributes['name'] := 'edge' + IntTostr(i);

    NewEdge.Source := 'node' + IntTostr(i);

    NewEdge.Target := 'node' + IntTostr(i+1);

  end;


    NewEdge := Graphml.Graph.Add.Edge.Add;

    NewEdge.Attributes['name'] := 'edge' + IntTostr(i);

    NewEdge.Source := 'node' + IntTostr(20);

    NewEdge.Target := 'node' + IntTostr(1);



  mmo1.Text := Graphml.Xml;
  XMLDoc.xml.SaveToFile('e:\test.xml');



  mmo1.lines.SaveToFile('e:\test_lib.graphml');
end;


OK, ich bekomme jetzt eine XML Datei, wenn ich das memo abspeichere.
Der aktuelle Fehler liegt aber in der Struktur der XML Datei. um jede Node oder Edge wird ein Begin/End <graph> Tag geschrieben, dies ist natürlich so falsch, wie kann man diesen Fehler beheben ??

Delphi-Quellcode:
<graphml><key id="KEY1" for="egde"/><key id="KEY2" for="node"/>

<graph>

<node name="node1"/>[B]</graph><graph>[/B]<node name="node2"/>[B]</graph><graph>[/B]
<node name="node3"/>[B]</graph><graph>[/B]<node name="node4"/>[B]</graph><graph>[/B]<node name="node5"/>

Geändert von bernhard_LA (28. Feb 2020 um 10:47 Uhr)
  Mit Zitat antworten Zitat
TiGü

Registriert seit: 6. Apr 2011
Ort: Berlin
3.058 Beiträge
 
Delphi 10.4 Sydney
 
#8

AW: Verwendung XML databinding wizard

  Alt 28. Feb 2020, 12:32
Zitat:
Der aktuelle Fehler liegt aber in der Struktur der XML Datei. um jede Node oder Edge wird ein Begin/End <graph> Tag geschrieben, dies ist natürlich so falsch, wie kann man diesen Fehler beheben ??
Schau doch mal, was da genau bei Graphml.Graph.Add.Node.Add; und Graphml.Graph.Add.Edge.Add; passiert.

Wenn du nur einmal den Node "graph" haben willst, solltest du auch nur einmal Graphml.Graph.Add aufrufen und das Result davon in eine Zwischenvariable abspeichern.
Da würde sich die dritte Zeile in der Variablendeklaration für anbieten (Graph: IXMLGraphtype;)
  Mit Zitat antworten Zitat
Themen-Optionen Thema durchsuchen
Thema durchsuchen:

Erweiterte Suche
Ansicht

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 14:16 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