C#--对象转成XML的方法

2021-06-01 13:05

阅读:453

标签:--   doc   builder   schema   replace   tostring   div   uil   string   

 public static XmlDocument JsonToXml(OrderDetail orderDetail)
        {
            XmlDocument document = new XmlDocument();
            StringBuilder sb = new StringBuilder();
            using (TextWriter tw = new StringWriter(sb))
            {
                var xmlS = new XmlSerializer(typeof(OrderDetail));
                xmlS.Serialize(tw, orderDetail);
                string serialized = sb.ToString();
                serialized = serialized.Replace(@"xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance""", "");
                serialized = serialized.Replace(@"xmlns:xsd=""http://www.w3.org/2001/XMLSchema""", "");
                document.LoadXml(serialized);
            }

            return document;
        }

 

C#--对象转成XML的方法

标签:--   doc   builder   schema   replace   tostring   div   uil   string   

原文地址:https://www.cnblogs.com/BounceGuo/p/10979618.html


评论


亲,登录后才可以留言!