I have created an api that gives the output in form of xml. It is used to give sitemap for the website. It just includes the following code
public class SitemapApiController : ApiController
{
public urlset GetSitemap()
{
// code for data access etc
return urlsetObj;
}
}
the urlset class is very simple
[XmlRoot("urlset")]
public class urlset: List<url>
{
}
the url class is as follows
public class url
{
public string loc { get; set; }
public DateTime lastmod { get; set; }
public double priority { get; set; }
}
Now my problem is that output is coming as
<arrayofurls>
<url>.....
while i want it to be
<urlset>
<url>....
I have read the similar posts for this, but to no relief. As stated in Modify the xml array element name in serialized ASP.NET WebAPI object post, if i use
[XmlArray("urlset")]
atribute over api controller, then it gives error that attribute "XmlArray" is not valid in this declaration type. Pls help me so that i can return valid sitemap from the api.
Edit
The output according to this is still a bit different. Now it shows
<urlset>
<url>
<url>
<loc>
<url>........
There is an extra needless url attribute as parent of all the url attributes.