title: How to add xsi schemalocation to root c # object XmlSerializer
body: <p>I am using XmlSerializer to create an object representing an XML file and now i want to add a schemalocation to the rootelement of my xml file.
  I can add namespaces like the following</p>
  
  <pre><code>        XmlSerializer serializer = new XmlSerializer(typeof(MyClass));
          System.IO.FileStream fs = new FileStream(@"C:\test.xml", FileMode.Create);
          TextWriter writer = new StreamWriter(fs, new UTF8Encoding());
  
          XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
          ns.Add("xy","http://www.w3.org/2005/08/addressing");
          ns.Add("xlink","http://www.w3.org/1999/xlink");
          serializer.Serialize(writer, myObject, ns);
  </code></pre>
  
  <p>But how do i add a <code>xsi:schemalocation</code> attribute to my root element within my c# code. Namespace was added with a simple <code>ns.Add()</code>. I would like to avoid messing around with the xsd.exe generated c# class.
  Or do i have to edit manually the generated c# class and add some attribute to the root element of my xml?</p>
  
  <p><strong>EDIT:</strong> I have seen examples where i need to edit my c# manually, but there must be a way to do it in code!! If we are able to add namespaces to our root element, why shouldn't it be possible to add schemalocations?</p>