In .NET 5 I setup a webserver with OWIN
public void ConfigureServices(IServiceCollection services)
{
services.AddControllers(options =>
{
options.RespectBrowserAcceptHeader = true;
}).AddXmlSerializerFormatters();
}
I have a Model PresEvents with a collection Events
public class PersEvents
{
public List<Event> Events { get; } = new List<Event>();
}
public class Event
{
public string Sn { get; set; } = string.Empty;
public string Loiname { get; set; } = string.Empty;
}
I have a controller returns this PersEvents instance
[HttpGet]
public PersEvents GetEventsData()
{
PersEvents events = new PersEvents();
events.Events.Add(new Event { Sn = "123", Loiname = "Ohio" });
events.Events.Add(new Event { Sn = "456", Loiname = "Ohio" });
return events;
}
When I call GetEventsData I can get the XML formatted data like below
<PersEvents xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Events>
<Event>
<Sn>123</Sn>
<Loiname>Ohio</Loiname>
</Event>
<Event>
<Sn>456</Sn>
<Loiname>Ohio</Loiname>
</Event>
</Events>
</PersEvents>
the question is I don't want the Events attribute, I just want all Event segments after PresEvents, How can I do that?