在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
http://blog.csdn.net/aoshilang2249/article/details/44860155
重点: XmlSerializerNamespaces namespaces = new XmlSerializerNamespaces();
namespaces.Add(string.Empty, string.Empty);
// 序列化这个对象 int obj = 1; XmlSerializer serializer = new XmlSerializer(obj.GetType()); // 将对象序列化输出到文件 FileStream stream = new FileStream("hh.xml", FileMode.Create); XmlWriterSettings settings = new XmlWriterSettings(); settings.Indent = true; settings.IndentChars = " "; settings.NewLineChars = "\r\n"; settings.Encoding = Encoding.UTF8; //settings.OmitXmlDeclaration = true; // 不生成声明头 using (XmlWriter xmlWriter = XmlWriter.Create(stream, settings)) { // 强制指定命名空间,覆盖默认的命名空间 XmlSerializerNamespaces namespaces = new XmlSerializerNamespaces(); namespaces.Add(string.Empty, string.Empty); serializer.Serialize(xmlWriter, obj, namespaces); xmlWriter.Close(); }; stream.Close();
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论