简体   繁体   中英

How to return a big XML response in C# Web API

I am creating a web api which need to create large XML responses according to various requests. I tried googling but all the answers are about XMLSerializer.
And I tried making XDocument object and returning it using toString() method. But it's not working properly too. It gives me output like this

<string xmlns="http://schemas.microsoft.com/2003/10/Serialization/"><root> <someNode>someValue</someNode> </root></string>

Isn't there an easy way to generate XML dynamically and return it.

Instead of generating XML dynamically, Why don't to use collection of class. Make a generic class and assign the data in collection. Send the collection using media header as xml.

request.Headers.Accept.Clear();
request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/xml"));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM