Adds support of XmlElement as one of the allowed objectType

This commit is contained in:
Jack Ma
2016-04-22 10:33:08 -07:00
parent 81098652b3
commit 795b9e3a46
@@ -1431,9 +1431,9 @@ namespace Newtonsoft.Json.Converters
#if !(DOTNET || PORTABLE) #if !(DOTNET || PORTABLE)
if (typeof(XmlNode).IsAssignableFrom(objectType)) if (typeof(XmlNode).IsAssignableFrom(objectType))
{ {
if (objectType != typeof(XmlDocument)) if (objectType != typeof(XmlDocument) && objectType != typeof(XmlElement))
{ {
throw new JsonSerializationException("XmlNodeConverter only supports deserializing XmlDocuments"); throw new JsonSerializationException("XmlNodeConverter only supports deserializing XmlDocuments or XmlElement");
} }
XmlDocument d = new XmlDocument(); XmlDocument d = new XmlDocument();
@@ -1477,6 +1477,11 @@ namespace Newtonsoft.Json.Converters
} }
#endif #endif
if (objectType == typeof(XmlElement))
{
return document.DocumentElement.WrappedNode;
}
return document.WrappedNode; return document.WrappedNode;
} }