Einzelnen Beitrag anzeigen

bernhard_LA

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

AW: Verwendung XML databinding wizard

  Alt 27. Feb 2020, 12: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