2
votes

I don't want the following to be appended to the root element

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">

what should I do when using XML serialization.

1
Yeah, me to, waiting for answers!Restuta

1 Answers

2
votes

By using the Serialize method:

public class Foo { }

class Program
{
    static void Main()
    {
        var foo = new Foo();
        var serializer = new XmlSerializer(foo.GetType());
        var ns = new XmlSerializerNamespaces();
        ns.Add(string.Empty, string.Empty);
        serializer.Serialize(Console.Out, foo, ns);
    }
}

Notice the last argument (ns).