有没有办法使序列化成员序列化为属性?

发布于 2024-08-29 10:28:48 字数 284 浏览 5 评论 0原文

有没有办法使序列化成员序列化为属性:

<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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

云醉月微眠 2024-09-05 10:28:48

我认为您正在寻找 XmlAttribute 属性:

<Serializable()> 
Public Class Person
    <Xml.Serialization.XmlAttribute()> 
    Public Property Name() As String
End Class

查看更多详细信息和 Xml 序列化属性 此处

I think you're looking for the XmlAttribute attribute:

<Serializable()> 
Public Class Person
    <Xml.Serialization.XmlAttribute()> 
    Public Property Name() As String
End Class

See more details and Xml-serialization attributes here.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文