0

我有 xml 包含:

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

为了使用 XmlSerializer 反序列化 xml,我需要向 Day 类添加哪些属性?

4

2 回答 2

1

以下装饰品——

[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; }
}

将序列化为:

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

希望这能让你有所收获。

凯夫

于 2009-01-24T18:38:40.763 回答
0
[XmlElement("day")]
public class Day
{
  [XmlAttribute("p")]
  public string P {get;set;}
}
于 2009-01-24T18:08:04.380 回答