Skip to main content
  1. Posts/

XML serialization libraries are deprecated

··2 mins

After building RSS.NET — my own RSS library for .NET — I realized I had solved the wrong problem.

The problem with format-specific libraries #

Take any of the popular XML format libraries from this era: RSS libraries, ATOM libraries, OPML libraries — including my own RSS.NET. Strip away the format names and they all implement the same pattern: read and write objects or structures to and from a specific XML file, abstracting raw XML away from the caller. Some operate on the whole document at once; others read and write incrementally. But the core contract is identical.

That repetition is the tell. When every format has its own hand-rolled library doing the same thing, the abstraction is in the wrong place.

The actual problem to solve #

These formats will evolve. New formats will appear. Each one will attract its own library, written from scratch, maintained separately, abandoned when the format shifts.

Building a library that reads and writes RSS 2.0 is not an investment — it’s a commitment to track every future revision of RSS 2.0.

The right abstraction is one level up: a library that generates format-specific libraries.

What that looks like #

Armed with an XML Schema and an object mapping file, a code generation library should produce a strongly-typed assembly whose sole purpose is to read and write a specific XML format. Once generated, developers work with concrete typed objects — not raw XML — along with formatReader and formatWriter objects for I/O.

The code generator targets the XML Schema standard, not any specific format. The same generator produces the RSS library, the ATOM library, the OPML library. When a format publishes a new schema version, you regenerate. The generator improves once; every derived library improves automatically.

The output objects should support both streaming (reading and writing a piece at a time via a stream) and whole-document operations. They should be schema-compliant and version-specific.

The result #

RSS, ATOM, and OPML objects that read and write their respective formats — generated, not handwritten. Schema-compliant, optimized per version, and easy for the end developer to use.

The tooling to do this partially exists already. xsd.exe /classes generates typed .NET classes from an XML Schema. What’s missing is the round-trip: a mapping layer that also generates the serialization logic from the schema, separating the format contract from the I/O implementation.

That gap is worth closing.

George Tsiokos
Author
George Tsiokos

Leave a comment

Preview

Comments are reviewed before publishing.