有没有办法使序列化成员序列化为属性?
有没有办法使序列化成员序列化为属性:
<Serializable>
Public Class Person
Public Property Name As String
End Class
我希望当此类是 xml 序列化时,它应该生成:
<Person Name="John Doe" />
我的意思是,不应将 Name 属性序列化为元素,而是应该将其序列化被序列化为 xml 属性。
Is there a way to make a serialized member to serialize as an attribute:
<Serializable>
Public Class Person
Public Property Name As String
End Class
I want than when this class is xml-serialized, it should produce:
<Person Name="John Doe" />
And what I mean is that instead of the Name property should be serialized as an element, it should be serialized as an xml attribute.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您正在寻找 XmlAttribute 属性:
查看更多详细信息和 Xml 序列化属性 此处。
I think you're looking for the XmlAttribute attribute:
See more details and Xml-serialization attributes here.