Delphi 2010 DeHL 序列化 XML 和自定义属性:如何工作?
我尝试使用 Delphi 2010 自定义属性调查 DeHL ,但遇到问题。
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;
这很好用:当我序列化时,我有这个,
<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
所以我想将自定义属性放入我的类中:
TAppParam = class
private
[XmlElement('Test')]
FTest: TAppParamTest;
public
constructor Create;
destructor Destroy; override;
property Test: TAppParamTest read FTest write FTest;
end;
但它无法编译:(
我在哪里犯了错误?
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
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 ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用:
[XmlName('测试')]
[XmlElement]
我更改了这些属性,因为它降低了序列化器中的代码复杂性。
Use:
[XmlName('Test')]
[XmlElement]
I changed these attributes since it reduced code complexity in the serializer.