views:

83

answers:

2

Hi

I have xml containing :

<day p="d">
<day p="n">

What attributes do I need to add to Day class in order to deserialize the xml with XmlSerializer?

A: 
[XmlElement("day")]
public class Day
{
  [XmlAttribute("p")]
  public string P {get;set;}
}
leppie
+1  A: 

The following decorations -

[XmlType(TypeName="day")]
public class Day
{
    [XmlAttribute("p")]
    public string P { get; set; }
}

[XmlRoot("someObject")]
public class SomeObject
{
    [XmlArray("days")]
    public List<Day> Days { get; set; }
}

Would serialise to:

<someObject xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
  <days>
    <day p="n" />
    <day p="p" />
  </days>
</someObject>

Hope that gets you somewhere.

Kev

Kev