Microsoft.AspNetCore.Mvc.Formatters.Xml.Extensions
2.2.0
See the version list below for details.
dotnet add package Microsoft.AspNetCore.Mvc.Formatters.Xml.Extensions --version 2.2.0
NuGet\Install-Package Microsoft.AspNetCore.Mvc.Formatters.Xml.Extensions -Version 2.2.0
<PackageReference Include="Microsoft.AspNetCore.Mvc.Formatters.Xml.Extensions" Version="2.2.0" />
paket add Microsoft.AspNetCore.Mvc.Formatters.Xml.Extensions --version 2.2.0
#r "nuget: Microsoft.AspNetCore.Mvc.Formatters.Xml.Extensions, 2.2.0"
// Install Microsoft.AspNetCore.Mvc.Formatters.Xml.Extensions as a Cake Addin #addin nuget:?package=Microsoft.AspNetCore.Mvc.Formatters.Xml.Extensions&version=2.2.0 // Install Microsoft.AspNetCore.Mvc.Formatters.Xml.Extensions as a Cake Tool #tool nuget:?package=Microsoft.AspNetCore.Mvc.Formatters.Xml.Extensions&version=2.2.0
ASP.NET Core MVC Xml formatter extensions
Nuget Package:
https://www.nuget.org/packages/Microsoft.AspNetCore.Mvc.Formatters.Xml.Extensions
ASP.NET Core MVC Xml formatter's extensions allow:
- ASP.NET MVC Core Web Application controller actions to control the Xml serialization type.
- Avoid the ObjectResult limitation to use only one type of MVC Xml serializer per ASP.NET MVC Core Web Application.
- Satisfy all possible Xml JAVA REST Web API and Xml .NET REST Web API communication scenarios.
XmlResult
An Action result which formats the given object as Xml.
- The XmlResult is the similar feature to JsonResult in the project "Microsoft.AspNetCore.Mvc.Formatters.Json".
- The property "XmlSerializerType" of the XmlResult defines which one of the MVC Xml formatters to use either XmlSerializer or DataContractSerializer.
- It allows to return Xml formatted response with using the HTTP Response Body.
"FromXmlBody"
Specifies an action parameter or property that should be bound with using the HTTP request Xml body.
- The FromBodyXmlAttribute is the similar attribute to FromBodyAttribute in the project "Microsoft.AspNetCore.Mvc".
- The property "XmlSerializerType" of the FromBodyXmlAttribute defines which one of the MVC Xml formatters to use either XmlSerializer or DataContractSerializer.
Example of using in the application:
Startup.cs
public void ConfigureServices(IServiceCollection services)
{
// Add framework services.
// "AddXmlFormaterExtensions()" initialize the Asp .Net Core MVC to use of XmlResult and FromXmlBody:
// - It adds the XmlSerializer and DataContractSerializer formatters to MVC.
// - It adds the XmlResult and FromXmlBody Extension to MVC.
services.AddMvc().AddXmlFormaterExtensions();
}
XmlExtController.cs(Example):
/// <summary>
/// The Controller example of using of XmlResult and FromXmlBody.
/// It demonstrates how to define which of the Xml formatters DataContractSerializer
/// or/and XmlSerializer to use for input and output in the Web Application controller actions.
/// </summary>
[Route("api/[controller]")]
public class XmlExtController : Controller
{
// GET api/[controller]/xml
[HttpGet("xml")]
public ActionResult GetXmlObject()
{
object obj = new PurchaseOrder();
return new XmlResult(obj);
}
// GET api/[controller]/dcxml
[HttpGet("dcxml")]
public ActionResult GetDcXmlObject()
{
object obj = new PurchaseOrder();
return new XmlResult(obj) { XmlSerializerType = XmlSerializerType.DataContractSerializer };
}
// POST api/[controller]/xml
[HttpPost("xml")]
public void PostXml([FromXmlBody]PurchaseOrder value)
{
var x = value;
x.billTo.street += " 123";
}
// POST api/[controller]/dcxml
[HttpPost("dcxml")]
public void PostDcXml([FromXmlBody(XmlSerializerType = XmlSerializerType.DataContractSerializer)]PurchaseOrder value)
{
var x = value;
x.billTo.street += "No -10";
}
}
Where the Models:
[DataContract (Namespace ="http://puchase.Interface.org/Purchase.Order")]
public class PurchaseOrder
{
public PurchaseOrder()
{
billTo = new Address() { street = "Bill to Address" };
shipTo = new Address() { street = "Ship to Address" };
}
[DataMember]
public Address billTo;
[DataMember]
public Address shipTo;
}
[DataContract(Namespace = "http://puchase.Interface.org/Purchase.Order.Address")]
public class Address
{
[DataMember]
public string street;
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Microsoft.AspNetCore.Mvc.Core (>= 2.2.0)
- Microsoft.AspNetCore.Mvc.Formatters.Xml (>= 2.2.0)
NuGet packages (2)
Showing the top 2 NuGet packages that depend on Microsoft.AspNetCore.Mvc.Formatters.Xml.Extensions:
Package | Downloads |
---|---|
EY.Common.NlogCoreLib
Package Description |
|
GraphQl.Extensions
GraphQl Extensions. Contains Xlsx output formatter, csv output formatter |
GitHub repositories
This package is not used by any popular GitHub repositories.
Released for Asp.NetCore.Mvc 2.2.0; NETStandard.Library 2.0.3