I was wondering what is best way to create XML output from MVC2 application and return it to client ( possibly also using XSD scheme validation) ?
I know i can’t return it directly from controller or pass to view as variable etc. Huge part of my application is doing conversion between different XML sources, schemas and formats so it’s really important that I setup this right from the beginning.
But is there any better way to do it?
Thanks in advance!
You could write a custom ActionResult which will serialize the view model into XML. Something among the lines:
and then:
Feel free to perform any XSD validations, etc… that you might need inside the
ExecuteResultmethod.As suggested by @Robert Koritnik in the comments section you could also write an extension method:
and then:
This being said if you find yourself in the need of exchanging lots of XML you might consider using WCF. And if you need POX, consider WCF REST.