使用XmlSerializer序列化多个类型的数组 [英] Serializing an array of multiple types using XmlSerializer
本文介绍了使用XmlSerializer序列化多个类型的数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用XMLSerializer生成如下的XML,其中< create>
的内容是一个数组,但是元素可以不同类型(在这种情况下,< vendor>
,< customer>
和<资产>
)。
I'm trying to use XMLSerializer to generate XML such as the following, where the contents of <create>
is an array, but the elements can be of differing types (in this case <vendor>
, <customer>
, and <asset>
). Is this possible?
...
<create>
<vendor>
<vendorid>Unit - A-1212</vendorid>
<name>this is the name8</name>
<vcf_bill_siteid3>FOOBAR8</vcf_bill_siteid3>
</vendor>
<customer>
<CUSTOMERID>XML121</CUSTOMERID>
<NAME>XML Customer 111</NAME>
</customer>
<asset>
<createdAt>San Jose</createdAt>
<createdBy>Kevin</createdBy>
<serial_number>123456789</serial_number>
</asset>
</create>
....
推荐答案
我结束了放弃XmlSerializer并使用Json.NET将对象序列化为json,然后转换为XML。
I ended up abandoning XmlSerializer and using Json.NET to serialize the object to json and then convert to XML.
这篇关于使用XmlSerializer序列化多个类型的数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文