Delphi 2010 DeHL Serialization XML and custom attribute : how it work?
I try to investigate DeHL with Delphi 2010 custom attribute and I get problem.
TAppParamTest = class
public
User: string;
Password: string;
end;
TAppParam = class
private
FTest: TAppParamTest;
public
constructor Create;
destructor Destroy; override;
property Test: TAppParamTest read FTest write FTest;
end;
this works well : when I serialize I have this
<TAppParam xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:DeHL="http://alex.ciobanu.org/DeHL.Serialization.XML" DeHL:class="AppParam_unt.TAppParam" DeHL:refid="1">
<FTest DeHL:class="AppParam_unt.TApp开发者_如何转开发ParamTest" DeHL:refid="2">
<User>User</User>
<Password>Psw</Password>
</FTest>
</TAppParam
but I want this :
<TAppParam xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:DeHL="http://alex.ciobanu.org/DeHL.Serialization.XML" DeHL:class="AppParam_unt.TAppParam" DeHL:refid="1">
<Test DeHL:class="AppParam_unt.TAppParamTest" DeHL:refid="2">
<User>User</User>
<Password>Psw</Password>
</Test>
</TAppParam
so I want to put custom attribute in my class :
TAppParam = class
private
[XmlElement('Test')]
FTest: TAppParamTest;
public
constructor Create;
destructor Destroy; override;
property Test: TAppParamTest read FTest write FTest;
end;
but it does not compile :(
Where I make mistake ?
Use:
[XmlName('Test')]
[XmlElement]
I changed these attributes since it reduced code complexity in the serializer.
精彩评论