I have a sample xml structure like:
<?xml version="1.0" encoding="iso-8859-1" ?>
<!DOCTYPE nzb PUBLIC "-//newzBin//DTD NZB 1.0//EN" "http://www.newzbin.com/DTD/nzb/nzb-1.0.dtd">
<nzb xmlns="http://www.newzbin.com/DTD/2003/nzb">
<file...>
</file>
<file...>
</file>
</nzb>
and .NET classes:
[XmlRoot(ElementName = "nzb")]
[XmlType("nzb")]
public class Nzb
{
[XmlElement(ElementName = "file")]
public FileData[] Files { get; set; } = [];
}
[XmlRoot(ElementName = "file")]
public class FileData
{
}
and I tried:
XmlSerializer serializer = new XmlSerializer(typeof(Nzb));
Nzb? obj = null;
using TextReader reader = new StringReader(File.ReadAllText(file));
obj = (Nzb)serializer.Deserialize(reader);
There is no way to get rid of namespace that can be different. I tried from here Error Deserializing Xml to Object – xmlns=” was not expected but still no success for my case.