[英]custom(?) serialization of list c#
I'm trying to convert a c# object containing a list into XML.我正在尝试将包含列表的 c# object 转换为 XML。 The list comes out fine as:该列表很好,如下所示:
<image>dummy</image>
<image>dummy2</image>
<image>dummy3</image>
and so forth.等等。 I want the tags to be unique like:我希望标签是独一无二的,例如:
<image_1>dummy</image_1>
<image_2>dummy2</image_2>
<image_3>dummy3</image_3>
But i'm not quite sure how to get to that result.但我不太确定如何得到这个结果。
Any input is appreciated:)任何输入表示赞赏:)
A rough sketch of a solution:解决方案的粗略草图:
Stream stream = ... // your output stream
XmlWriter xml = new XmlWriter(stream)
xml.WriteStartDocument();
int index = 0;
foreach (var x in list) {
xml.WriteStringElement("index_" + index++, x.ToString());
}
xml.Close();
https://docs.microsoft.com/en-us/dotnet/api/system.xml.xmlwriter?view=netcore-3.1 https://docs.microsoft.com/en-us/dotnet/api/system.xml.xmlwriter?view=netcore-3.1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.