liveBook · Manning

XML formatting

As explained in Pro ASP.NET Core 7, Tenth Edition

XML formatting is the serialization of application data into XML representations for transmission in responses.

XML formatting serializes controller responses as XML when ASP.NET Core MVC has an XML formatter available and content negotiation selects it. Add XML support alongside JSON in Program.cs: AddControllers().AddNewtonsoftJson().AddXmlDataContractSerializerFormatters(). section 20.4.2

Account for these practical behaviors:

  • Return an XML-serializable object such as ProductBindingTarget rather than an Entity Framework Core entity with interface-based navigation properties. section 20.4.2

Requesting XML

Invoke-WebRequest http://localhost:5000/api/content/object -Headers @{Accept="application/xml"} returns Content-Type application/xml; charset=utf-8 and a ProductBindingTarget element containing Name, Price, CategoryId, and SupplierId.

How Pro ASP.NET Core 7, Tenth Edition covers it

How deep it goes
Explains registration, Accept-header requests, serializer limitations, and rejection behavior, but only briefly mentions custom formatter development.
Examples
Uses Program.cs registration, a ProductBindingTarget controller response, PowerShell requests, and XML or JSON response output.
What it assumes
Assumes an ASP.NET Core MVC application with controllers and introduces XML support through the existing formatter configuration.
What you can do after
Configure XML formatting and verify negotiated responses with PowerShell requests and response Content-Type values.
How it connects
Connects XML formatting to content negotiation, Accept headers, JSON, output formatters, and Entity Framework Core navigation properties.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Pro ASP.NET Core 7, Tenth Edition. The section links point to the parts of the book it draws on.