c#:如何将几个字符串转换XML格式。比较急!!
2个回答
展开全部
是字符串数组吗?
参考代码:
string[] arr = 你的字符串数组;
XmlSerializer formatter = new XmlSerializer(arr.GetType());
using (MemoryStream memory = new MemoryStream())
using (XmlTextWriter xmlTextWriter = new XmlTextWriter(memory, Encoding.UTF8))
{
formatter.Serialize(xmlTextWriter, arr);
using (MemoryStream mem2 = (MemoryStream) xmlTextWriter.BaseStream)
{
string ret = Encoding.UTF8.GetString(mem2.ToArray());
return ret;// 这个ret就是你要的xml了
}
}
参考代码:
string[] arr = 你的字符串数组;
XmlSerializer formatter = new XmlSerializer(arr.GetType());
using (MemoryStream memory = new MemoryStream())
using (XmlTextWriter xmlTextWriter = new XmlTextWriter(memory, Encoding.UTF8))
{
formatter.Serialize(xmlTextWriter, arr);
using (MemoryStream mem2 = (MemoryStream) xmlTextWriter.BaseStream)
{
string ret = Encoding.UTF8.GetString(mem2.ToArray());
return ret;// 这个ret就是你要的xml了
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询