2011-02-18 14:51:00 +00:00
|
|
|
{
|
|
|
|
X2Software XML Data Binding
|
|
|
|
|
2011-03-07 09:05:09 +00:00
|
|
|
Generated on: 3-3-2011 12:45:23
|
2011-02-18 14:51:00 +00:00
|
|
|
Generated from: P:\test\X2Utils\XSD\PersistXML.xsd
|
|
|
|
}
|
|
|
|
unit X2UtPersistXMLBinding;
|
|
|
|
|
|
|
|
interface
|
|
|
|
uses
|
|
|
|
Classes,
|
|
|
|
XMLDoc,
|
|
|
|
XMLIntf,
|
|
|
|
XMLDataBindingUtils;
|
|
|
|
|
|
|
|
type
|
|
|
|
{ Forward declarations for PersistXML }
|
|
|
|
IXMLSection = interface;
|
|
|
|
IXMLvalueList = interface;
|
|
|
|
IXMLsectionList = interface;
|
2011-03-07 09:05:09 +00:00
|
|
|
IXMLValue = interface;
|
2011-02-18 14:51:00 +00:00
|
|
|
IXMLConfiguration = interface;
|
|
|
|
|
|
|
|
{ Interfaces for PersistXML }
|
|
|
|
IXMLSection = interface(IXMLNode)
|
2011-03-07 09:05:09 +00:00
|
|
|
['{810C68EC-1138-4B89-A164-9F9B03970771}']
|
2011-02-18 14:51:00 +00:00
|
|
|
function Getsection: IXMLsectionList;
|
|
|
|
function Getvalue: IXMLvalueList;
|
|
|
|
function GetHasname: Boolean;
|
|
|
|
function Getname: WideString;
|
|
|
|
|
|
|
|
procedure Setname(const Value: WideString);
|
|
|
|
|
|
|
|
property section: IXMLsectionList read Getsection;
|
|
|
|
property value: IXMLvalueList read Getvalue;
|
|
|
|
property Hasname: Boolean read GetHasname;
|
|
|
|
property name: WideString read Getname write Setname;
|
|
|
|
end;
|
|
|
|
|
|
|
|
IXMLvalueList = interface(IXMLNodeCollection)
|
2011-03-07 09:05:09 +00:00
|
|
|
['{93139658-6A8B-46DE-B7B9-734A6A94762A}']
|
|
|
|
function Get_value(Index: Integer): IXMLValue;
|
|
|
|
function Add: IXMLValue;
|
|
|
|
function Insert(Index: Integer): IXMLValue;
|
2011-02-18 14:51:00 +00:00
|
|
|
|
2011-03-07 09:05:09 +00:00
|
|
|
property value[Index: Integer]: IXMLValue read Get_value; default;
|
2011-02-18 14:51:00 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
IXMLsectionList = interface(IXMLNodeCollection)
|
2011-03-07 09:05:09 +00:00
|
|
|
['{C6BFF503-B4F0-492B-9B60-B97140D59782}']
|
2011-02-18 14:51:00 +00:00
|
|
|
function Get_section(Index: Integer): IXMLSection;
|
|
|
|
function Add: IXMLSection;
|
|
|
|
function Insert(Index: Integer): IXMLSection;
|
|
|
|
|
|
|
|
property section[Index: Integer]: IXMLSection read Get_section; default;
|
|
|
|
end;
|
|
|
|
|
2011-03-07 09:05:09 +00:00
|
|
|
IXMLValue = interface(IXMLNode)
|
|
|
|
['{3F92F545-4FA7-43AD-A623-113BD9100FE2}']
|
|
|
|
function GetHasinteger: Boolean;
|
|
|
|
function Getinteger: Integer;
|
|
|
|
function GetHasfloat: Boolean;
|
|
|
|
function Getfloat: Double;
|
|
|
|
function GetHas_string: Boolean;
|
|
|
|
function Get_string: WideString;
|
|
|
|
function GetHasvariant: Boolean;
|
|
|
|
function GetvariantIsNil: Boolean;
|
|
|
|
function Getvariant: WideString;
|
|
|
|
function GetHasint64: Boolean;
|
|
|
|
function Getint64: Int64;
|
2011-02-18 14:51:00 +00:00
|
|
|
function GetHasname: Boolean;
|
|
|
|
function Getname: WideString;
|
|
|
|
|
2011-03-07 09:05:09 +00:00
|
|
|
procedure Setinteger(const Value: Integer);
|
|
|
|
procedure Setfloat(const Value: Double);
|
|
|
|
procedure Set_string(const Value: WideString);
|
|
|
|
procedure SetvariantIsNil(const Value: Boolean);
|
|
|
|
procedure Setvariant(const Value: WideString);
|
|
|
|
procedure Setint64(const Value: Int64);
|
2011-02-18 14:51:00 +00:00
|
|
|
procedure Setname(const Value: WideString);
|
|
|
|
|
2011-03-07 09:05:09 +00:00
|
|
|
property Hasinteger: Boolean read GetHasinteger;
|
|
|
|
property integer: Integer read Getinteger write Setinteger;
|
|
|
|
property Hasfloat: Boolean read GetHasfloat;
|
|
|
|
property float: Double read Getfloat write Setfloat;
|
|
|
|
property Has_string: Boolean read GetHas_string;
|
|
|
|
property _string: WideString read Get_string write Set_string;
|
|
|
|
property Hasvariant: Boolean read GetHasvariant;
|
|
|
|
property variantIsNil: Boolean read GetvariantIsNil write SetvariantIsNil;
|
|
|
|
property variant: WideString read Getvariant write Setvariant;
|
|
|
|
property Hasint64: Boolean read GetHasint64;
|
|
|
|
property int64: Int64 read Getint64 write Setint64;
|
2011-02-18 14:51:00 +00:00
|
|
|
property Hasname: Boolean read GetHasname;
|
|
|
|
property name: WideString read Getname write Setname;
|
|
|
|
end;
|
|
|
|
|
|
|
|
IXMLConfiguration = interface(IXMLSection)
|
2011-03-07 09:05:09 +00:00
|
|
|
['{AE639E63-960C-445F-89D8-53866535F725}']
|
2011-02-18 14:51:00 +00:00
|
|
|
procedure XSDValidateDocument;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
{ Classes for PersistXML }
|
|
|
|
TXMLSection = class(TXMLNode, IXMLSection)
|
|
|
|
private
|
|
|
|
Fsection: IXMLsectionList;
|
|
|
|
Fvalue: IXMLvalueList;
|
|
|
|
public
|
|
|
|
procedure AfterConstruction; override;
|
|
|
|
protected
|
|
|
|
function Getsection: IXMLsectionList;
|
|
|
|
function Getvalue: IXMLvalueList;
|
|
|
|
function GetHasname: Boolean;
|
|
|
|
function Getname: WideString;
|
|
|
|
|
|
|
|
procedure Setname(const Value: WideString);
|
|
|
|
end;
|
|
|
|
|
|
|
|
TXMLvalueList = class(TXMLNodeCollection, IXMLvalueList)
|
|
|
|
public
|
|
|
|
procedure AfterConstruction; override;
|
|
|
|
protected
|
2011-03-07 09:05:09 +00:00
|
|
|
function Get_value(Index: Integer): IXMLValue;
|
|
|
|
function Add: IXMLValue;
|
|
|
|
function Insert(Index: Integer): IXMLValue;
|
2011-02-18 14:51:00 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
TXMLsectionList = class(TXMLNodeCollection, IXMLsectionList)
|
|
|
|
public
|
|
|
|
procedure AfterConstruction; override;
|
|
|
|
protected
|
|
|
|
function Get_section(Index: Integer): IXMLSection;
|
|
|
|
function Add: IXMLSection;
|
|
|
|
function Insert(Index: Integer): IXMLSection;
|
|
|
|
end;
|
|
|
|
|
2011-03-07 09:05:09 +00:00
|
|
|
TXMLValue = class(TXMLNode, IXMLValue)
|
2011-02-18 14:51:00 +00:00
|
|
|
protected
|
2011-03-07 09:05:09 +00:00
|
|
|
function GetHasinteger: Boolean;
|
|
|
|
function Getinteger: Integer;
|
|
|
|
function GetHasfloat: Boolean;
|
|
|
|
function Getfloat: Double;
|
|
|
|
function GetHas_string: Boolean;
|
|
|
|
function Get_string: WideString;
|
|
|
|
function GetHasvariant: Boolean;
|
|
|
|
function GetvariantIsNil: Boolean;
|
|
|
|
function Getvariant: WideString;
|
|
|
|
function GetHasint64: Boolean;
|
|
|
|
function Getint64: Int64;
|
2011-02-18 14:51:00 +00:00
|
|
|
function GetHasname: Boolean;
|
|
|
|
function Getname: WideString;
|
|
|
|
|
2011-03-07 09:05:09 +00:00
|
|
|
procedure Setinteger(const Value: Integer);
|
|
|
|
procedure Setfloat(const Value: Double);
|
|
|
|
procedure Set_string(const Value: WideString);
|
|
|
|
procedure SetvariantIsNil(const Value: Boolean);
|
|
|
|
procedure Setvariant(const Value: WideString);
|
|
|
|
procedure Setint64(const Value: Int64);
|
2011-02-18 14:51:00 +00:00
|
|
|
procedure Setname(const Value: WideString);
|
|
|
|
end;
|
|
|
|
|
|
|
|
TXMLConfiguration = class(TXMLSection, IXMLConfiguration)
|
|
|
|
protected
|
|
|
|
procedure XSDValidateDocument;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
{ Document functions }
|
|
|
|
function GetConfiguration(ADocument: XMLIntf.IXMLDocument): IXMLConfiguration;
|
|
|
|
function LoadConfiguration(const AFileName: String): IXMLConfiguration;
|
|
|
|
function LoadConfigurationFromStream(AStream: TStream): IXMLConfiguration;
|
|
|
|
function NewConfiguration: IXMLConfiguration;
|
|
|
|
|
|
|
|
|
|
|
|
const
|
|
|
|
TargetNamespace = '';
|
|
|
|
|
|
|
|
|
|
|
|
implementation
|
|
|
|
uses
|
|
|
|
SysUtils;
|
|
|
|
|
|
|
|
{ Document functions }
|
|
|
|
function GetConfiguration(ADocument: XMLIntf.IXMLDocument): IXMLConfiguration;
|
|
|
|
begin
|
|
|
|
Result := ADocument.GetDocBinding('Configuration', TXMLConfiguration, TargetNamespace) as IXMLConfiguration
|
|
|
|
end;
|
|
|
|
|
|
|
|
function LoadConfiguration(const AFileName: String): IXMLConfiguration;
|
|
|
|
begin
|
|
|
|
Result := LoadXMLDocument(AFileName).GetDocBinding('Configuration', TXMLConfiguration, TargetNamespace) as IXMLConfiguration
|
|
|
|
end;
|
|
|
|
|
|
|
|
function LoadConfigurationFromStream(AStream: TStream): IXMLConfiguration;
|
|
|
|
var
|
|
|
|
doc: XMLIntf.IXMLDocument;
|
|
|
|
|
|
|
|
begin
|
|
|
|
doc := NewXMLDocument;
|
|
|
|
doc.LoadFromStream(AStream);
|
|
|
|
Result := GetConfiguration(doc);
|
|
|
|
end;
|
|
|
|
|
|
|
|
function NewConfiguration: IXMLConfiguration;
|
|
|
|
begin
|
|
|
|
Result := NewXMLDocument.GetDocBinding('Configuration', TXMLConfiguration, TargetNamespace) as IXMLConfiguration
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
{ Implementation for PersistXML }
|
|
|
|
procedure TXMLSection.AfterConstruction;
|
|
|
|
begin
|
|
|
|
RegisterChildNode('section', TXMLSection);
|
|
|
|
Fsection := CreateCollection(TXMLsectionList, IXMLSection, 'section') as IXMLsectionList;
|
|
|
|
RegisterChildNode('section', TXMLSection);
|
2011-03-07 09:05:09 +00:00
|
|
|
RegisterChildNode('value', TXMLValue);
|
|
|
|
Fvalue := CreateCollection(TXMLvalueList, IXMLValue, 'value') as IXMLvalueList;
|
|
|
|
RegisterChildNode('value', TXMLValue);
|
2011-02-18 14:51:00 +00:00
|
|
|
inherited;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TXMLSection.Getsection: IXMLsectionList;
|
|
|
|
begin
|
|
|
|
Result := Fsection;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TXMLSection.Getvalue: IXMLvalueList;
|
|
|
|
begin
|
|
|
|
Result := Fvalue;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TXMLSection.GetHasname: Boolean;
|
|
|
|
begin
|
|
|
|
Result := Assigned(AttributeNodes.FindNode('name'));
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function TXMLSection.Getname: WideString;
|
|
|
|
begin
|
|
|
|
Result := AttributeNodes['name'].Text;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TXMLSection.Setname(const Value: WideString);
|
|
|
|
begin
|
|
|
|
SetAttribute('name', Value);
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TXMLvalueList.AfterConstruction;
|
|
|
|
begin
|
2011-03-07 09:05:09 +00:00
|
|
|
RegisterChildNode('value', TXMLValue);
|
2011-02-18 14:51:00 +00:00
|
|
|
|
|
|
|
ItemTag := 'value';
|
2011-03-07 09:05:09 +00:00
|
|
|
ItemInterface := IXMLValue;
|
2011-02-18 14:51:00 +00:00
|
|
|
|
|
|
|
inherited;
|
|
|
|
end;
|
|
|
|
|
2011-03-07 09:05:09 +00:00
|
|
|
function TXMLvalueList.Get_value(Index: Integer): IXMLValue;
|
2011-02-18 14:51:00 +00:00
|
|
|
begin
|
2011-03-07 09:05:09 +00:00
|
|
|
Result := (List[Index] as IXMLValue);
|
2011-02-18 14:51:00 +00:00
|
|
|
end;
|
|
|
|
|
2011-03-07 09:05:09 +00:00
|
|
|
function TXMLvalueList.Add: IXMLValue;
|
2011-02-18 14:51:00 +00:00
|
|
|
begin
|
2011-03-07 09:05:09 +00:00
|
|
|
Result := (AddItem(-1) as IXMLValue);
|
2011-02-18 14:51:00 +00:00
|
|
|
end;
|
|
|
|
|
2011-03-07 09:05:09 +00:00
|
|
|
function TXMLvalueList.Insert(Index: Integer): IXMLValue;
|
2011-02-18 14:51:00 +00:00
|
|
|
begin
|
2011-03-07 09:05:09 +00:00
|
|
|
Result := (AddItem(Index) as IXMLValue);
|
2011-02-18 14:51:00 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TXMLsectionList.AfterConstruction;
|
|
|
|
begin
|
|
|
|
RegisterChildNode('section', TXMLSection);
|
|
|
|
|
|
|
|
ItemTag := 'section';
|
|
|
|
ItemInterface := IXMLSection;
|
|
|
|
|
|
|
|
inherited;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TXMLsectionList.Get_section(Index: Integer): IXMLSection;
|
|
|
|
begin
|
|
|
|
Result := (List[Index] as IXMLSection);
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TXMLsectionList.Add: IXMLSection;
|
|
|
|
begin
|
|
|
|
Result := (AddItem(-1) as IXMLSection);
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TXMLsectionList.Insert(Index: Integer): IXMLSection;
|
|
|
|
begin
|
|
|
|
Result := (AddItem(Index) as IXMLSection);
|
|
|
|
end;
|
|
|
|
|
2011-03-07 09:05:09 +00:00
|
|
|
function TXMLValue.GetHasinteger: Boolean;
|
|
|
|
begin
|
|
|
|
Result := Assigned(ChildNodes.FindNode('integer'));
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function TXMLValue.Getinteger: Integer;
|
|
|
|
begin
|
|
|
|
Result := ChildNodes['integer'].NodeValue;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TXMLValue.GetHasfloat: Boolean;
|
|
|
|
begin
|
|
|
|
Result := Assigned(ChildNodes.FindNode('float'));
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function TXMLValue.Getfloat: Double;
|
|
|
|
begin
|
|
|
|
Result := XMLToFloat(ChildNodes['float'].NodeValue);
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TXMLValue.GetHas_string: Boolean;
|
|
|
|
begin
|
|
|
|
Result := Assigned(ChildNodes.FindNode('string'));
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function TXMLValue.Get_string: WideString;
|
|
|
|
begin
|
|
|
|
Result := ChildNodes['string'].Text;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TXMLValue.GetHasvariant: Boolean;
|
|
|
|
begin
|
|
|
|
Result := Assigned(ChildNodes.FindNode('variant'));
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function TXMLValue.GetvariantIsNil: Boolean;
|
|
|
|
begin
|
|
|
|
Result := GetNodeIsNil(ChildNodes['variant']);
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function TXMLValue.Getvariant: WideString;
|
|
|
|
begin
|
|
|
|
Result := ChildNodes['variant'].Text;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TXMLValue.GetHasint64: Boolean;
|
|
|
|
begin
|
|
|
|
Result := Assigned(ChildNodes.FindNode('int64'));
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function TXMLValue.Getint64: Int64;
|
|
|
|
begin
|
|
|
|
Result := ChildNodes['int64'].NodeValue;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TXMLValue.GetHasname: Boolean;
|
2011-02-18 14:51:00 +00:00
|
|
|
begin
|
|
|
|
Result := Assigned(AttributeNodes.FindNode('name'));
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2011-03-07 09:05:09 +00:00
|
|
|
function TXMLValue.Getname: WideString;
|
2011-02-18 14:51:00 +00:00
|
|
|
begin
|
|
|
|
Result := AttributeNodes['name'].Text;
|
|
|
|
end;
|
|
|
|
|
2011-03-07 09:05:09 +00:00
|
|
|
procedure TXMLValue.Setinteger(const Value: Integer);
|
|
|
|
begin
|
|
|
|
ChildNodes['integer'].NodeValue := Value;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TXMLValue.Setfloat(const Value: Double);
|
|
|
|
begin
|
|
|
|
ChildNodes['float'].NodeValue := FloatToXML(Value);
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TXMLValue.Set_string(const Value: WideString);
|
|
|
|
begin
|
|
|
|
ChildNodes['string'].NodeValue := Value;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TXMLValue.SetvariantIsNil(const Value: Boolean);
|
|
|
|
begin
|
|
|
|
SetNodeIsNil(ChildNodes['variant'], Value);
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TXMLValue.Setvariant(const Value: WideString);
|
|
|
|
begin
|
|
|
|
ChildNodes['variant'].NodeValue := Value;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TXMLValue.Setint64(const Value: Int64);
|
|
|
|
begin
|
|
|
|
ChildNodes['int64'].NodeValue := Value;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TXMLValue.Setname(const Value: WideString);
|
2011-02-18 14:51:00 +00:00
|
|
|
begin
|
|
|
|
SetAttribute('name', Value);
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TXMLConfiguration.XSDValidateDocument;
|
|
|
|
begin
|
|
|
|
XMLDataBindingUtils.XSDValidate(Self);
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
end.
|