Serialize an object in c# with XmlSerializer by removing xml schema elements.

Posted by jineesh uvantavida on Tuesday, November 14, 2017 Under: c#
Serialize an object in c# with XmlSerializer by removing xml schema elements such as xmlns:xsi

        string content =String.Empty;
XmlDocument xmlDoc = new XmlDocument();
        XmlSerializer xmlSerializer = new XmlSerializer(obj.GetType());
        using (MemoryStream xmlStream = new MemoryStream())
        {
            var ns = new XmlSerializerNamespaces();
            ns.Add("", "");
            xmlSerializer.Serialize(xmlStream, obj, ns);
            xmlStream.Position = 0;
            //Loads the XML document from the specified string.
            xmlDoc.Load(xmlStream);
            content = xmlDoc.InnerXml;
        }

In : c# 


Tags: xml serialization  xmlns:sxi 

Translate This Page

 


Make a free website with Yola