Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Deserialize XmlDocument to object
/// <summary>
/// Deserializes XmlDocument object to Serializable object of type T.
/// </summary>
/// <typeparam name="T">Serializable object type as output type.</typeparam>
/// <param name="document">XmlDocument object to be deserialized.</param>
/// <returns>Deserialized serializable object of type T.</returns>
public static T Deserialize<T>(this XmlDocument document)
where T : class
XmlReader reader = new XmlNodeReader(document);
var serializer = new XmlSerializer(typeof(T));
T result = (T)serializer.Deserialize(reader);
return result;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.