Search code examples
c#xml-namespacesxml-deserialization

C# Deserializer using System.Xml.Serialization namespace with prefix issue


I have this xml that I'm trying to deserialize into a class, but I can't create the proper class that works. The xml is:

<?xml version="1.0" encoding="ISO-8859-1"?>
    <AnswersPP s="DSD" lst="11/22/2016 1:08:39 PM" n="1">
      <Results xmlns:ssud="www.solacestar.ud>
         <ssud:starlist>
             <ssud:star id="4234234">
                 <span style="white-space: nowrap">#NOMA, MAJOR</span>
             </<ssud:star>
             <ssud:star id="2352234">
                 <span style="white-space: nowrap">#NOMA, MINOR</span>
             </<ssud:star>
         </ssud:starlist>
       </Results>
       <Error/>
     </AnswersPP>

What I have is:

[XmlRoot("AnswersPP")]
public class AMDResponseDto
{
    [XmlElement("Results")]
    public Results Results { get; set; }

    [XmlElement("Error")]
    public Error Error { get; set; }
}
public class Results
{
    [XmlElement("starlist")]
    public StarList StarList { get; set; }
}
public class StarList
{
    [XmlElement("star")]
    public List<Star> Data { get; set; }
}
public class Star
{
    [XmlAttribute("id")]
    public string Id { get; set; }
}

I know it's the namespace that's tripping me up, but nothing I've tried works. Does anyone know what I need to do?


Solution

  • Simply had to add Namespace in the XMLAttribute and XmlElement annotations.