开发者

How to Deserialize xml with muliple matching nodes to array in c#

I want to deserialise an xml document with a number of same name nodes into an IList in c# I do not have control over the xml and ther开发者_开发技巧efore cant change it.

<root>
 <node1 name="" version="" />
 <node1 name="" version="" />
 <node1 name="" version="" />
 <node1 name="" version="" />
 <node2></node2>
 <node3></node3>
</root>

I have two classes Root and Node1 which look like:

[XmlRoot("root")]
public class Root
{
 public IList<Node1> Node1List { get; set; }

 [XmlElement("node2")]
 public string Node2 { get; set; }

 [XmlElement("node3")]
 public string Node3 { get; set; }
}

[XmlRoot("node1")]
public class Node1
{


 [XmlAttribute("name")]
 public string Name{ get; set; }

 [XmlAttribute("version")]
 public string Version{ get; set; }
}

Any Ideas how I can deserialise the xml so that all node1 elements are part of Node1List?


Add XmlElement: (you may need to remove [XmlRoot("node1")])

[XmlElement("node1")]
public List<Node1> Node1List { get; set; }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜