//XMLFile1.xml
<root>
<goods>
<item type = "1">
<param>10001</param>
<param>5</param>
</item>
<item type = "3">
<param>10004</param>
<param>10</param>
</item>
<goods>
</root>
using System.Xml;
public class XmlDataGoods
{
public int type;
public int[] param;
}
public List<XmlDataGoods> LoadXml()
{
List<XmlDataGoods> data = new List<XmlDataGoods>();
XmlDocument doc = new XmlDocument();
doc.Load("XMLFile1.xml");
XmlNode root = doc.SelectSingleNode("goods");
XmlNodeList nodeList = root.SelectNodes("item");
for (int i = 0; i < nodeList.Count; ++i)
{
XmlDataGoods goods = new XmlDataGoods();
XmlNode node = nodeList[i];
XmlElement element = (XmlElement)node;
goods.type = Convert.ToInt32(element.GetAttribute("type"));
XmlNodeList childNodes = node.ChildNodes;
goods.param = new int[childNodes.Count];
for (int j = 0; j < childNodes.Count; ++j)
{
goods.param[j] = Convert.ToInt32(childNodes[j].InnerText);
}
data.Add(goods);
}
return data;
}