7
我無法搞清楚了這一點,我有一個XML紙張看起來像這樣XML序列化陣列
<root>
<list id="1" title="One">
<word>TEST1</word>
<word>TEST2</word>
<word>TEST3</word>
<word>TEST4</word>
<word>TEST5</word>
<word>TEST6</word>
</list>
<list id="2" title="Two">
<word>TEST1</word>
<word>TEST2</word>
<word>TEST3</word>
<word>TEST4</word>
<word>TEST5</word>
<word>TEST6</word>
</list>
</root>
而且我想它序列化到
public class Items
{
[XmlAttribute("id")]
public string ID { get; set; }
[XmlAttribute("title")]
public string Title { get; set; }
//I don't know what to do for this
[Xml... something]
public list<string> Words { get; set; }
}
//I don't this this is right either
[XmlRoot("root")]
public class Lists
{
[XmlArray("list")]
[XmlArrayItem("word")]
public List<Items> Get { get; set; }
}
//Deserialize XML to Lists Class
using (Stream s = File.OpenRead("myfile.xml"))
{
Lists myLists = (Lists) new XmlSerializer(typeof (Lists)).Deserialize(s);
}
我對XML和XML序列化來說真的很新,任何幫助都將不勝感激
使用XmlArray的單詞屬性它應該工作 – sll
只需注意一點,如果您將XML轉換爲對象,那就是反序列化。將對象轉換爲XML(或可以發送到磁盤或網絡蒸汽的任何其他格式)是序列化。 – MCattle