使用 XmlSerializer 序列化名称值对数组而不包含节点
我有这个类...
[XmlRoot("config")]
public class SourceConfig
{
public string Description { get; set; }
public string HelpLink { get; set; }
}
...我将其序列化到这个...
<config>
<Description />
<HelpLink />
<param name="param1" value="" />
<param name="param2" value="" />
</config>
...使用 XmlSerializer
+ 使用 XmlDocument
进行后处理来添加 < ;param>
元素。
是否有更好的方法来序列化 元素,而无需使用
XmlDocument
进行后处理?
我尝试使用 XmlArray
属性,但 元素最终位于另一个节点内。
I have this class...
[XmlRoot("config")]
public class SourceConfig
{
public string Description { get; set; }
public string HelpLink { get; set; }
}
...which I serialize into this...
<config>
<Description />
<HelpLink />
<param name="param1" value="" />
<param name="param2" value="" />
</config>
...using XmlSerializer
+ post-process using XmlDocument
to add the <param>
elements.
Is there a better way to serialize the <param>
elements without post-processing using XmlDocument
?
I tried using XmlArray
attribute but the <param>
elements ended up inside another node.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使其成为 XmlElement:
完整工作示例:
输出以下内容:
Make it an XmlElement:
Complete working example:
Outputs the following: