79812541

Date: 2025-11-07 16:06:07
Score: 0.5
Natty:
Report link

Unlike many, I have no particular beef with XML. I like XML. I think it’s got a couple of things on JSON and it’s fine. But when you start dealing with namespaces and schemas, you’re getting yourself into some enterprisey territory that you wouldn’t wish on anyone. You can surely understand it all, or you can just fuck around until stuff works. I opt for the latter, so here are some changes that should make your results look the way you want.

1. Use AddXmlSerializerFormatters()

This uses the older XmlSerializer from System.Xml.Serialization and will honor your class and member attributes.

builder.Services.AddControllers().AddXmlSerializerFormatters();

2. If you want your attribs to say xsi:, give them the namespace

[XmlAttribute("schemaLocation", Namespace = "http://www.w3.org/2001/XMLSchema-instance")]
public string SchemaLocation { get; set; }

3. Tell the Controller to output XML

[Produces("application/xml")]
public ActionResult GetXmlResponse()
{
    var sample = new Nautix
    { /* … */ };

    return Ok(sample);
}

I think that should be all. I removed Script because I don’t have the class.

Output:

<nautix xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.3"
        origin="Api.Catamarans.com"
        date="2025-11-07T10:00:00.1403438+02:00"
        xsi:schemaLocation="https://nautix.nautic-network.org/v1.3/ https://nautix.nautic-network.org/v1.3/NautiX.xsd">
    <account token="101">
        <account_name>Catamarans.com</account_name>
    </account>
</nautix>

If you must have the date without the fractional seconds, just use an additional string property and control the formatting to your liking.

Reasons:
  • Blacklisted phrase (2): fuck
  • Long answer (-1):
  • Has code block (-0.5):
Posted by: BenderBoy