⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 test.pas

📁 XML 精要 范例 解析封装类库
💻 PAS
字号:

{*****************************************************}
{                                                     }
{                  XML Data Binding                   }
{                                                     }
{         Generated on: 2004-01-03 18:06:51           }
{       Generated from: D:\AppServ\www\xml\test.xml   }
{   Settings stored in: D:\AppServ\www\xml\test.xdb   }
{                                                     }
{*****************************************************}

unit test;

interface

uses xmldom, XMLDoc, XMLIntf;

type

{ Forward Decls }

  IXMLXMLPackageType = interface;
  IXMLClinetinfoType = interface;
  IXMLDataType = interface;
  IXMLRowType = interface;
  IXMLMemoType = interface;
  IXMLActionsType = interface;

{ IXMLXMLPackageType }

  IXMLXMLPackageType = interface(IXMLNode)
    ['{3C0245EF-B99A-49C9-BE17-EF16F1BF627E}']
    { Property Accessors }
    function Get_Clinetinfo: IXMLClinetinfoType;
    function Get_Data: IXMLDataType;
    function Get_Memo: IXMLMemoType;
    function Get_Actions: IXMLActionsType;
    { Methods & Properties }
    property Clinetinfo: IXMLClinetinfoType read Get_Clinetinfo;
    property Data: IXMLDataType read Get_Data;
    property Memo: IXMLMemoType read Get_Memo;
    property Actions: IXMLActionsType read Get_Actions;
  end;

{ IXMLClinetinfoType }

  IXMLClinetinfoType = interface(IXMLNode)
    ['{8084B22B-C9B5-452B-AD75-6A8973FE3800}']
    { Property Accessors }
    function Get_Ip: WideString;
    function Get_Handler: WideString;
    function Get_Unit_: WideString;
    procedure Set_Ip(Value: WideString);
    procedure Set_Handler(Value: WideString);
    procedure Set_Unit_(Value: WideString);
    { Methods & Properties }
    property Ip: WideString read Get_Ip write Set_Ip;
    property Handler: WideString read Get_Handler write Set_Handler;
    property Unit_: WideString read Get_Unit_ write Set_Unit_;
  end;

{ IXMLDataType }

  IXMLDataType = interface(IXMLNodeCollection)
    ['{9E0632B3-25D7-48D9-912B-C7128D7D8523}']
    { Property Accessors }
    function Get_Row(Index: Integer): IXMLRowType;
    { Methods & Properties }
    function Add: IXMLRowType;
    function Insert(const Index: Integer): IXMLRowType;
    property Row[Index: Integer]: IXMLRowType read Get_Row; default;
  end;

{ IXMLRowType }

  IXMLRowType = interface(IXMLNode)
    ['{8C79E5D1-816C-4081-A98C-A90E7206F58E}']
    { Property Accessors }
    function Get_Id: Integer;
    function Get_Name: WideString;
    function Get_Sex: WideString;
    function Get_Age: Integer;
    function Get_Duty: WideString;
    procedure Set_Id(Value: Integer);
    procedure Set_Name(Value: WideString);
    procedure Set_Sex(Value: WideString);
    procedure Set_Age(Value: Integer);
    procedure Set_Duty(Value: WideString);
    { Methods & Properties }
    property Id: Integer read Get_Id write Set_Id;
    property Name: WideString read Get_Name write Set_Name;
    property Sex: WideString read Get_Sex write Set_Sex;
    property Age: Integer read Get_Age write Set_Age;
    property Duty: WideString read Get_Duty write Set_Duty;
  end;

{ IXMLMemoType }

  IXMLMemoType = interface(IXMLNode)
    ['{EBED1028-3B8C-4C03-914C-C861BC32F211}']
    { Property Accessors }
    function Get_Length: Integer;
    function Get_Color: WideString;
    procedure Set_Length(Value: Integer);
    procedure Set_Color(Value: WideString);
    { Methods & Properties }
    property Length: Integer read Get_Length write Set_Length;
    property Color: WideString read Get_Color write Set_Color;
  end;

{ IXMLActionsType }

  IXMLActionsType = interface(IXMLNode)
    ['{A991F602-DBE5-4A03-9223-0243BB785381}']
    { Property Accessors }
    function Get_Acition: WideString;
    procedure Set_Acition(Value: WideString);
    { Methods & Properties }
    property Acition: WideString read Get_Acition write Set_Acition;
  end;

{ Forward Decls }

  TXMLXMLPackageType = class;
  TXMLClinetinfoType = class;
  TXMLDataType = class;
  TXMLRowType = class;
  TXMLMemoType = class;
  TXMLActionsType = class;

{ TXMLXMLPackageType }

  TXMLXMLPackageType = class(TXMLNode, IXMLXMLPackageType)
  protected
    { IXMLXMLPackageType }
    function Get_Clinetinfo: IXMLClinetinfoType;
    function Get_Data: IXMLDataType;
    function Get_Memo: IXMLMemoType;
    function Get_Actions: IXMLActionsType;
  public
    procedure AfterConstruction; override;
  end;

{ TXMLClinetinfoType }

  TXMLClinetinfoType = class(TXMLNode, IXMLClinetinfoType)
  protected
    { IXMLClinetinfoType }
    function Get_Ip: WideString;
    function Get_Handler: WideString;
    function Get_Unit_: WideString;
    procedure Set_Ip(Value: WideString);
    procedure Set_Handler(Value: WideString);
    procedure Set_Unit_(Value: WideString);
  end;

{ TXMLDataType }

  TXMLDataType = class(TXMLNodeCollection, IXMLDataType)
  protected
    { IXMLDataType }
    function Get_Row(Index: Integer): IXMLRowType;
    function Add: IXMLRowType;
    function Insert(const Index: Integer): IXMLRowType;
  public
    procedure AfterConstruction; override;
  end;

{ TXMLRowType }

  TXMLRowType = class(TXMLNode, IXMLRowType)
  protected
    { IXMLRowType }
    function Get_Id: Integer;
    function Get_Name: WideString;
    function Get_Sex: WideString;
    function Get_Age: Integer;
    function Get_Duty: WideString;
    procedure Set_Id(Value: Integer);
    procedure Set_Name(Value: WideString);
    procedure Set_Sex(Value: WideString);
    procedure Set_Age(Value: Integer);
    procedure Set_Duty(Value: WideString);
  end;

{ TXMLMemoType }

  TXMLMemoType = class(TXMLNode, IXMLMemoType)
  protected
    { IXMLMemoType }
    function Get_Length: Integer;
    function Get_Color: WideString;
    procedure Set_Length(Value: Integer);
    procedure Set_Color(Value: WideString);
  end;

{ TXMLActionsType }

  TXMLActionsType = class(TXMLNode, IXMLActionsType)
  protected
    { IXMLActionsType }
    function Get_Acition: WideString;
    procedure Set_Acition(Value: WideString);
  end;

{ Global Functions }

function GetXMLPackage(Doc: IXMLDocument): IXMLXMLPackageType;
function LoadXMLPackage(const FileName: WideString): IXMLXMLPackageType;
function NewXMLPackage: IXMLXMLPackageType;

const
  TargetNamespace = '';

implementation

{ Global Functions }

function GetXMLPackage(Doc: IXMLDocument): IXMLXMLPackageType;
begin
  Result := Doc.GetDocBinding('XMLPackage', TXMLXMLPackageType, TargetNamespace) as IXMLXMLPackageType;
end;

function LoadXMLPackage(const FileName: WideString): IXMLXMLPackageType;
begin
  Result := LoadXMLDocument(FileName).GetDocBinding('XMLPackage', TXMLXMLPackageType, TargetNamespace) as IXMLXMLPackageType;
end;

function NewXMLPackage: IXMLXMLPackageType;
begin
  Result := NewXMLDocument.GetDocBinding('XMLPackage', TXMLXMLPackageType, TargetNamespace) as IXMLXMLPackageType;
end;

{ TXMLXMLPackageType }

procedure TXMLXMLPackageType.AfterConstruction;
begin
  RegisterChildNode('clinetinfo', TXMLClinetinfoType);
  RegisterChildNode('data', TXMLDataType);
  RegisterChildNode('memo', TXMLMemoType);
  RegisterChildNode('actions', TXMLActionsType);
  inherited;
end;

function TXMLXMLPackageType.Get_Clinetinfo: IXMLClinetinfoType;
begin
  Result := ChildNodes['clinetinfo'] as IXMLClinetinfoType;
end;

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

function TXMLXMLPackageType.Get_Memo: IXMLMemoType;
begin
  Result := ChildNodes['memo'] as IXMLMemoType;
end;

function TXMLXMLPackageType.Get_Actions: IXMLActionsType;
begin
  Result := ChildNodes['actions'] as IXMLActionsType;
end;

{ TXMLClinetinfoType }

function TXMLClinetinfoType.Get_Ip: WideString;
begin
  Result := AttributeNodes['ip'].Text;
end;

procedure TXMLClinetinfoType.Set_Ip(Value: WideString);
begin
  SetAttribute('ip', Value);
end;

function TXMLClinetinfoType.Get_Handler: WideString;
begin
  Result := AttributeNodes['handler'].Text;
end;

procedure TXMLClinetinfoType.Set_Handler(Value: WideString);
begin
  SetAttribute('handler', Value);
end;

function TXMLClinetinfoType.Get_Unit_: WideString;
begin
  Result := AttributeNodes['unit'].Text;
end;

procedure TXMLClinetinfoType.Set_Unit_(Value: WideString);
begin
  SetAttribute('unit', Value);
end;

{ TXMLDataType }

procedure TXMLDataType.AfterConstruction;
begin
  RegisterChildNode('row', TXMLRowType);
  ItemTag := 'row';
  ItemInterface := IXMLRowType;
  inherited;
end;

function TXMLDataType.Get_Row(Index: Integer): IXMLRowType;
begin
  Result := List[Index] as IXMLRowType;
end;

function TXMLDataType.Add: IXMLRowType;
begin
  Result := AddItem(-1) as IXMLRowType;
end;

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

{ TXMLRowType }

function TXMLRowType.Get_Id: Integer;
begin
  Result := AttributeNodes['id'].NodeValue;
end;

procedure TXMLRowType.Set_Id(Value: Integer);
begin
  SetAttribute('id', Value);
end;

function TXMLRowType.Get_Name: WideString;
begin
  Result := AttributeNodes['name'].Text;
end;

procedure TXMLRowType.Set_Name(Value: WideString);
begin
  SetAttribute('name', Value);
end;

function TXMLRowType.Get_Sex: WideString;
begin
  Result := AttributeNodes['sex'].Text;
end;

procedure TXMLRowType.Set_Sex(Value: WideString);
begin
  SetAttribute('sex', Value);
end;

function TXMLRowType.Get_Age: Integer;
begin
  Result := AttributeNodes['age'].NodeValue;
end;

procedure TXMLRowType.Set_Age(Value: Integer);
begin
  SetAttribute('age', Value);
end;

function TXMLRowType.Get_Duty: WideString;
begin
  Result := AttributeNodes['duty'].Text;
end;

procedure TXMLRowType.Set_Duty(Value: WideString);
begin
  SetAttribute('duty', Value);
end;

{ TXMLMemoType }

function TXMLMemoType.Get_Length: Integer;
begin
  Result := AttributeNodes['length'].NodeValue;
end;

procedure TXMLMemoType.Set_Length(Value: Integer);
begin
  SetAttribute('length', Value);
end;

function TXMLMemoType.Get_Color: WideString;
begin
  Result := AttributeNodes['color'].Text;
end;

procedure TXMLMemoType.Set_Color(Value: WideString);
begin
  SetAttribute('color', Value);
end;

{ TXMLActionsType }

function TXMLActionsType.Get_Acition: WideString;
begin
  Result := AttributeNodes['acition'].Text;
end;

procedure TXMLActionsType.Set_Acition(Value: WideString);
begin
  SetAttribute('acition', Value);
end;

end. 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -