I am using XmlSerializer to deserialize XML, and sometimes have to deal with legacy files with slight differences, for example "yes" where "Yes" is expected, i.e.
Expected: <Enabled>yes</Enabled>
Actual: <Enabled>Yes</Enabled>
This causes an "InvalidOperationException" and terminates the deserialization. I would prefer my code to be able to examine the cause of the exception, and recover and continue if possible. What is the best way to achieve this?
Many thanks
Max
> I am using XmlSerializer to deserialize XML, and sometimes have to deal with legacy files with slight differences, for example "yes" where "Yes" is expected, i.e.
>
[quoted text clipped - 3 lines]
>
> This causes an "InvalidOperationException" and terminates the deserialization. I would prefer my code to be able to examine the cause of the exception, and recover and continue if possible. What is the best way to achieve this?
Why <Enabled> and not <Enabled>? And why is Yes a problem? That
depends solely on the type definition for the Enabled element
respectively property.
I am not sure there is a way to recover, I rather think you need to find
a way to transform the "legacy" XML to the current XML. XSLT is one way
to do that.

Signature
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/