a.rlx
a.rlx

Reputation: 54

Multiple Versions C# classes/XSD using XSD.exe

I am using XSD.exe to convert a pretty complex XML-Schema (XSD-file) to C# Classes. I am then using XmlSerializer to read XML into memory and work with the data.

In the future, the XSD will change. So there will be a new version. I will have to create a new cs file with XSD.exe. But I still want to support the old versions of XML files as well.

What is the best way to go about this and support both the old and new versions of XML files? Obviously, the classes XSD.exe creates will have the same names. So I can't really just generate another cs file in parallel with XSD.exe.

Any ideas are welcome. Thanks in advance!

Upvotes: 2

Views: 524

Answers (3)

a.rlx
a.rlx

Reputation: 54

Thank you for your answers.

For now, I placed the Code generated by XSD.exe in separate Namespaces and have them derive from a base class.

Like this, I can use either one or the other Class for generating/reading the XML. It appears to be working for me right now, as the Schema will not change without a new Version. Any changes made will be put into a new Version.

Upvotes: -1

Liquid Support Team
Liquid Support Team

Reputation: 301

XML Data Binding has the advantage of enabling you to code against strongly typed classes rather than untyped nodes, but this can make versioning tricky.

Information about this can be found in the 'Schema Versioning' section of Liquid XML Data Binder 2021 - Getting Started documentation.

Upvotes: 2

Michael Kay
Michael Kay

Reputation: 163272

Data binding technologies (that convert XSD definitions into types in a strongly-typed programming language) are an absolute pain when the schema is large, complex, or changing. My strong advice would be, find a different approach. I've earned a lot of consulting money helping people dig themselves out of this hole.

Use technologies that are better at coping with change and variety. XSLT, XQuery, LINQ, or even DOM if you must. XSLT and XQuery come with schema-awareness as an option so you can get some of the benefits (having your program code checked against the schema) without the heavy price of rebuilding and retesting your application every time there's a change.

Upvotes: 1

Related Questions