1

I have following code which converts Object into XML and it working fine.

    public static string ConvertObjectToXML(Object obj)
    {
        String XmlizedString = null;
        MemoryStream memoryStream = new MemoryStream();
        XmlSerializer xs = null;

            if (obj is DerivedClass2)
            {
                xs = new XmlSerializer(typeof(DerivedClass2));
            }

        TextWriter w = new StringWriter();
        //this.s = new XmlSerializer(this.type);
        xs.Serialize(w, notoficationOrder);
        w.Flush();
        //return w;
        XmlizedString = w.ToString();
        w.Close();
        return XmlizedString.Trim();
   }

And it gives following output

<?xml version="1.0" encoding="utf-16"?>*   
<Obj xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <List>
        <!--...-->
    </List>
</Obj>

But I do not want XML which depicts Xml Namespace xd etc. I need only pure Object output of as below

<Obj>
  <List>
     <!--...-->
  </List>
</Obj>

Thanks

Ocean

H.B.
  • 166,899
  • 29
  • 327
  • 400
Ocean
  • 655
  • 2
  • 8
  • 21
  • possible duplicate question: http://stackoverflow.com/questions/625927/omitting-all-xsi-and-xsd-namespaces-when-serializing-an-object-in-net – Jimmy Chandra Feb 17 '11 at 19:02
  • I can understand you want this, but there is a reason they exist. To avoid a crash when two elements have the same name, but are different objects. – Mikael Svenson Feb 17 '11 at 19:04

1 Answers1

1

How to PROPERLY remove xmln:xsi and xmlns:xsd from xml dictionary serialization

This is VB .NET but the idea is the same.

Community
  • 1
  • 1
Dan Abramov
  • 264,556
  • 84
  • 409
  • 511