.Net对象序列化为XML,去掉NameSpace和XML开头,用于微信消息应答

作者:admin 时间:2015/2/12 13:49:15 访问量:922

/// <summary>
        /// 转换成为XML
        /// </summary>
        /// <returns></returns>
        public virtual string ToXml()
        {
            this.CreateTime = DateTime.Now.Ticks;

            XmlSerializer xsSubmit = new XmlSerializer(this.GetType());
            XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
            ns.Add("", "");
            StringWriter sw = new StringWriter();
            XmlWriterSettings settings = new XmlWriterSettings();
            settings.OmitXmlDeclaration = true;
            XmlWriter writer = XmlWriter.Create(sw, settings);
            xsSubmit.Serialize(writer, this, ns);
            return sw.ToString();
        }
可以返回符合微信消息的XML
返回顶部