<books>
<class1 Name = "a" Owner="JJ">
<class2 Name = "a1" Owner="JJ">
</class2>
<class2 Name = "a2" Owner="JJ">
</class2>
<class1 Name = "a3" Owner="JJ">
<class2 Name = "a4" Owner="JJ">
</class2>
</class1>
</class1>
<class1 Name = "b" Owner="JJ">
<class2 Name = "b1" Owner="JJ">
</class2>
</class1>
</books>
public class book
{
public string Name{get;set}
public string Owner{ger;set}
public ObservableCollection<book> Children {get;set}
}如何将xml中的内容填充到List<book>中呢?我主要是Children这不清楚..本人菜鸟,求解答
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(@"E:\Test\10test\10\10\XMLFile1.xml");
XmlNode xn = xmlDoc.SelectSingleNode("doc//person");
Hashtable list = new Hashtable();
int index = 0;
getchird(list, xn);
foreach(DictionaryEntry aa in list)
{
Console.WriteLine("KEY="+aa.Key + " VALUE="+aa.Value+"/n");
}
}
public static void getchird(Hashtable list, XmlNode nodes )
{
XmlNodeList xnl = nodes.ChildNodes;
if (xnl.Count != 0)
{
foreach (XmlNode node in xnl)
{
if (!node.HasChildNodes)
{
list.Add(node.OuterXml, node.InnerText);
}
else
{
getchird(list, node);
}
}
}
}