I have some XML in the following format:
<PurchaseItem>
<Name>Item 1</Name>
<Costs>
<Cost>
<Code>A</Code>
<Info>Test 1</Info>
</Cost>
<Cost>
<Code>B</Code>
<Info>Test 1</Info>
</Cost>
<Cost>
<Code>C</Code>
<Info>Test 1</Info>
</Cost>
</Costs>
</PurchaseItem>
I want this XML to deserialize into the following class:
public class PurchaseItem
{
[XmlElement("Name")]
public string Name { get; set; }
[XmlElement("Costs")]
public Cost[] Costs { get; set; }
}
public class Cost
{
[XmlElement("Code")]
public string Code{ get; set; }
[XmlElement("Info")]
public string Info{ get; set; }
}
However I cannot seem to get this to work unless I make another class to be a wrapper for the Cost[]
.
How can I have the cost array be serialized in the PurchaseItem
class as in the code above?