C# deserializing xml with multiple possible namespaces

I created an API wrapper class library for consuming a rest API from a 3rd party.

It was all working until they recently updated the API in the latest version of their product and added a namespace to the root element, now my deserialization code is failing.

An example of one of my classes:

[Serializable]
[XmlRootAttribute(ElementName = "exit_survey_list")]
public class SupportExitSurveyCollection : ApiResult { .... }

If I set the Namespace property in the XmlRootAttribute to the new namespace being returned, then it works properly again.

But I need to support both versions of the API (namespaced and not) because I cannot be sure which version of the API will be available.

I'd like to get this working without duplicating classes for different versions, but not sure if it's possible.

Thanks for any input/advice.

8
задан Adam 11 February 2011 в 17:48
поделиться