using System.Collections.Generic;
using System.Xml.Serialization;
using System.Diagnostics;
[XmlRoot("rootObject", Namespace = "http://www.example.com/xmlschemas/nonStandardSchema")]
public static XmlSerializerNamespaces GetAdditionalNamespaces()
XmlSerializerNamespaces xsNS = new XmlSerializerNamespaces();
xsNS.Add("", "http://www.example.com/xmlschemas/nonStandardSchema");
xsNS.Add("xsi", "http://www.w3.org/2001/XMLSchema-instance");
[XmlAttribute("schemaLocation", Namespace = "http://www.w3.org/2001/XMLSchema-instance")]
public string XSDSchemaLocation
return "http://www.example.com/xmlschemas/nonStandardSchema1.xsd";
public Object[] OtherSerializedObjects { get; set; }
OtherSerializedObjects = new Object[]{};
public static void Main()
var rootObject = new RootObject
OtherSerializedObjects = new object[]{}
var serializer = new XmlSerializer(typeof(RootObject));
var stringWriter = new StringWriter();
var ns = RootObject.GetAdditionalNamespaces();
var settings = new XmlWriterSettings() { Indent = true, IndentChars = " " };
using (var xmlWriter = XmlWriter.Create(stringWriter, settings))
serializer.Serialize(xmlWriter, rootObject, ns);
Console.WriteLine(stringWriter.ToString());