Reputation: 4865
Consider the following scenario. We have a XSD file defining a technical document interchange format (one root type composed of several complexTypes
).
Additionally, there is a specification defining defining each and every field with value range and format.
Obviously, both documents have been created by different departments because the formats are defined differently. E.g.
XmlSerializer
format: HH:mm:ss.fff)Technical wise, things are easy. We used XSD.exe to generate the classes. But now the output file is looking different after using XmlSerializer
. There is no chance to negotiate the format, since it was created due to a regulation affecting a whole market and therefore a lot of counterparties.
As per the moment we have to assume, that the formats of the specification document need to be respected. So I was looking for options to ensure this.
IXmlSerializable
interface to the generated classes of the affected complexTypes
. XmlSerializer
is throwing an exception: "There was an error reflecting type." XPathNavigator
after serialization. partial class
, right?I've ordered the list by the order of preference.
So did I miss an option? Which way would you go?
I know it's not the typical How do I use class xyz question, but still I'm hoping, that you can give me hint, how such kind of scenarios are handled usually.
Upvotes: 0
Views: 124
Reputation: 4865
Due to the tremendous feedback, I've decided to go with option 3.
Reason is simple. We can still use the standard class generation with XSD.exe and keep all benefits of XmlSerializer
class.
For more information please refer to this article in the MSDN. The flow is pretty straight forward.
We have tested it already and it's working like a charm.
Upvotes: 0