public class Request
{
[XmlArrayItem(ElementName = "fieldtype", IsNullable = true)]
[XmlArrayItem(ElementName = "field", IsNullable = true)]
[XmlArray]
public string[] requestkind { get; set; }
//[XmlArray]
public string[] field { get; set; }
public string[] fieldtype { get; set; }
public string[] medtype { get; set; }
public string[] patient { get; set; }
}
怎么才能序列化成如下的xml文档呢?序列化我会,但是不知道怎么嵌套,
<Request>
<requestkind>
<field>
<fieldtype>
<medtype/>
</fieldtype>
</field>
<field>
<fieldtype>
<medtype/>
</fieldtype>
</field>
</requestkind>
<requestkind>
<field>
<fieldtype>
<medtype/>
</fieldtype>
</field>
<field>
<fieldtype>
<medtype/>
</fieldtype>
</field>
</requestkind>
<requestkind>
<field>
<fieldtype>
<medtype/>
</fieldtype>
</field>
<field>
<fieldtype>
<medtype/>
</fieldtype>
</field>
</requestkind>
</Request>
请各位帮帮忙吧,谢谢!!!
{
[XmlArrayItem(ElementName = "fieldtype", IsNullable = true)]
[XmlArrayItem(ElementName = "field", IsNullable = true)]
[XmlArray]
public string[] requestkind { get; set; }
//[XmlArray]
public string[] field { get; set; }
public string[] fieldtype { get; set; }
public string[] medtype { get; set; }
public string[] patient { get; set; }
}
怎么才能序列化成如下的xml文档呢?序列化我会,但是不知道怎么嵌套,
<Request>
<requestkind>
<field>
<fieldtype>
<medtype/>
</fieldtype>
</field>
<field>
<fieldtype>
<medtype/>
</fieldtype>
</field>
</requestkind>
<requestkind>
<field>
<fieldtype>
<medtype/>
</fieldtype>
</field>
<field>
<fieldtype>
<medtype/>
</fieldtype>
</field>
</requestkind>
<requestkind>
<field>
<fieldtype>
<medtype/>
</fieldtype>
</field>
<field>
<fieldtype>
<medtype/>
</fieldtype>
</field>
</requestkind>
</Request>
请各位帮帮忙吧,谢谢!!!
{
XmlSerializer xs = new XmlSerializer(typeof(UpdateConfig));
if (File.Exists(file))
{
StreamReader sr = new StreamReader(file);
UpdateConfig config = (UpdateConfig)xs.Deserialize(sr);
sr.Close();
return config;
}
else
{
return null;
}
} public void SaveConfig(string file)
{
XmlSerializer xs = new XmlSerializer(typeof(UpdateConfig));
StreamWriter sw = new StreamWriter(file);
xs.Serialize(sw, this);
sw.Close();
}