using (var ms = new MemoryStream())
{
ClassA tryXml = new ClassA {Key = "A", Value = "1"};
XmlSerializer serializer = new XmlSerializer(typeof (ClassA));
serializer.Serialize(ms, tryXml);
var xmlClass = new XmlDocument();
xmlClass.LoadXml(Encoding.UTF8.GetString(ms.ToArray()));
var xmlDocument = new XmlDocument();
xmlDocument.Load("C:\\temp\\TryXml.xml");
XmlElement element = xmlDocument.CreateElement("ClassA");
element.InnerXml = xmlClass.DocumentElement.InnerXml;
xmlDocument.SelectSingleNode("/configuration").AppendChild(element);
xmlDocument.Save("C:\\temp\\TryXml.xml");
}
如何在一个XML中插入序列化的类
最新推荐文章于 2024-08-19 17:10:10 发布