[英]Serialize object as element with value of its field
I have a class which needs to be serialized, it has the only 1 field to store a value:我有一个需要序列化的类,它只有 1 个字段来存储值:
public class Element
{
public int Value { get; set; }
}
And it is saved as(btw: it's not a root element):它被保存为(顺便说一句:它不是根元素):
<Element>
<Value>123</Value>
</Element>
However I need to get a bit another xml:但是我需要再获取一点 xml:
<Element>123</Element>
Serialization is performed using System.Xml.Serialization.XmlSerializer.使用 System.Xml.Serialization.XmlSerializer 执行序列化。 Is there any possibility to omit the Value -element and pass its value to Element ?
是否有可能省略Value元素并将其值传递给Element ?
Just include XmlText
attribute.只需包含
XmlText
属性。 That is all.就这些。
public class Element
{
[XmlText]
public int Value { get; set; }
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.