你的位置:首页 > ASP.net教程

[ASP.net教程]Xml序列化去掉命名空间,去掉申明


#region 序列化
        /// <summary>
        /// 序列化
        /// </summary>
        /// <param name="type">类型</param>
        /// <param name="obj">对象</param>
        /// <returns></returns>
        public  string Serializer(Type type, object obj)
        {
            MemoryStream Stream = new MemoryStream();
                        ns.Add("", "");//把命名空间设置为空,这样就没有命名空间了
                        try
            {
                //序列化对象
                            }
            catch (InvalidOperationException)
            {
                throw;
            }
            Stream.Position = 0;
            StreamReader sr = new StreamReader(Stream);
            string str = sr.ReadToEnd();

            sr.Dispose();
            Stream.Dispose();

            return str;
        }

        #endregion

 

 public static string ObjectTonew //去除true;      settings.Encoding = Encoding.Default;      System.IO.MemoryStream mem = new MemoryStream();      using ( //去除默认命名空间new "", "");        new return Encoding.Default.GetString(mem.ToArray());    }
源网址:http://www.cnblogs.com/kissdodog/archive/2013/12/10/3468385.html