大家好,我有 2 个这样的课程:
[XmlRoot("Config")]
public class ConfigClass
{
[XmlElement("Configuration1")]
public string Config1 { get; set; }
[XmlArray("Infos")]
[XmlArrayItem("Info")]
public OtherInfo[] OtherInfos { get; set; }
}
public class OtherInfo
{
public string Info1 { get; set; }
public string Info2 { get; set; }
}
当我序列化根类时,XML 结果是这样的:
<?xml version="1.0"?>
<Config>
<Configuration1>Text</Configuration1>
<Infos>
<Info>
<Info1>Test 2</Info1>
<Info2>Text 3</Info2>
</Info>
<Info>
<Info1>Test 4</Info1>
<Info2>Text 5</Info2>
</Info>
</Infos>
</Config>
但我希望OtherInfo
该类被序列化为这样的单个字符串:
<?xml version="1.0"?>
<Config>
<Configuration1>Text</Configuration1>
<Infos>
<Info>
Test 2:Text 3
</Info>
<Info>
Test 4:Text 5
</Info>
</Infos>
</Config>
我怎么能这样做?