Delphi 2010 DeHL序列化XML和自定义属性:如何工作? [英] Delphi 2010 DeHL Serialization XML and custom attribute : how it work?
本文介绍了Delphi 2010 DeHL序列化XML和自定义属性:如何工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试使用Delphi 2010自定义属性调查 DeHL ,但出现问题。
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.TAppParamTest" DeHL:refid="2">
<User>User</User>
<Password>Psw</Password>
</FTest>
</TAppParam
但我想要这个:
<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;
但它不会编译:(
我在哪里弄错了?
推荐答案
使用:
[XmlName('Test') ]
[XmlElement]
我更改了这些属性,因为它减少了序列化程序中的代码复杂度。
I changed these attributes since it reduced code complexity in the serializer.
这篇关于Delphi 2010 DeHL序列化XML和自定义属性:如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文