I am trying to deserialize the following xml
-
The problem is that the namespace of myrootNS class is incorrect because it doesn't match the expected namespace in the XML.
[XmlRoot("myroot", Namespace = "http://jeson.com/")]
public class myrootNS
{
[XmlElement(Namespace = "")]
public item[] item { get; set; }
}
Notice that the Namespace
property value has a trailing /. This is my deserialize method:
static T Deserialize(string xml)
{
XmlSerializer serializer = new XmlSerializer(typeof(T));
XmlReaderSettings settings = new XmlReaderSettings();
using (StringReader textReader = new StringReader(xml))
{
using (XmlReader xmlReader = XmlReader.Create(textReader, settings))
{
return (T)serializer.Deserialize(xmlReader);
}
}
}