日期:2014-05-18 浏览次数:21237 次
using ( Stream stream = new MemoryStream()) { XmlSerializer xmlSerializer = new XmlSerializer(typeof(test)); xmlSerializer.Serialize(stream, instance); XmlDocument objectDoc = new XmlDocument(); [color=#FF0000]objectDoc.Load(stream); //发生异常,XmlException 缺少根元素。[/color] XmlNode node = objectDoc.SelectSingleNode(typeof(T).Name); InsertToConfigFile(node); }