Quantcast
Viewing all articles
Browse latest Browse all 4

Answer by Merlyn Morgan-Graham for How to handle multiple XML versions gracefully

Multiple Parsers

If you have X versions of the schema, you'll need X code paths to handle them.

To pick your implementation you're going to have to have a switch statement somewhere. That switch could simply call methods, or it could be in a factory method that returns the correct parser (class or delegate).

This doesn't preclude you from sharing parts of your code between versions, and it is a good idea to break down your parsing into its component parts in order to support this. You can break them down via classes or via methods.

You could have a common base interface to kick off parsing any version, and get back the object graph that the XML represents. The resulting object model should ideally be as version independent as possible so you can share common functionality.

Upgrading Data

Alternately you could use XSLT to upgrade the data, and use only one parser.

You can either implement this once for each version and chain all the transforms, or you can transform directly to the latest version and modify previous version's transforms with every release.

Chaining transforms has better maintenance cost. Direct transform has better perf.

You'll still need a switch for this :)


Viewing all articles
Browse latest Browse all 4

Trending Articles