This response is delayed for one year and tested on WebAPI2!
Enable XML Declaration in WebApiConfig
config.Formatters.XmlFormatter.WriterSettings.OmitXmlDeclaration = false;
Then add the schemaLocation property or member (I always prefer the property)
public class SampleData { [XmlAttribute(AttributeName = "schemaLocation", Namespace = "http://www.w3.org/2001/XMLSchema-instance")] public string SchemaLocation { get; set; } //other properties public string Prop1 { get; set; } public SampleData() { SchemaLocation = "http://localhost/my.xsd"; } }
Conclusion:
<?xml version="1.0" encoding="utf-8"?> <TestModel xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xsi:schemaLocation="http://localhost/my.xsd"> <Prop1>1</Prop1> </TestModel>
source share