In a Nancy .Net REST web-service I need to be able to specify a custom xmlns:xsd for the root element of the xml-tree that is produced when I use the code below – is this possible?:
public class RequestModule : NancyModule
{
Get["/books"] = parameters =>
{
return Response.AsXml(List<Book>);
};
}
Calling /books using the code above produces output similar to…
<ArrayOfBook
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Book>
...
</Book>
...
</ArrayOfBook>
Does Nancy provide the possibilty of changing the values of xmlns:xsd to some custom schema url? So I would get something like…
<ArrayOfBook
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://myschemaurl.com/2007/MyCustomXMLSchema">
<Book>
...
</Book>
...
</ArrayOfBook>
If the above is not possible with Nancy out of the box, could someone point me to the location in the Nancy framework source code where I could change code to achieve my goal?
Response.AsXml is just a fancy helper to return XML. You can return a Response object on your own and set the ContentType and Content to what ever content you want. Use what ever serializer you want and just stick it in a response and off you go
If you want to use Response.AsXml then you should look at implementing an ISerializer and registering it in the Bootstrapper -> InternalConfiguration => Serializers. Response.AsXml will use the first ISerializer that say it can handle the xml media type