110,538
社区成员
发帖
与我相关
我的任务
分享
<pre>
<root>
<result>0</result>
<orderLists>
<orderList>
<olNbr>1</olNbr>
<soDate>2011-03-11 20:00:00</soDate >
<description>Kobe has five championRings</description>
</orderList>
<orderList>
<olNbr>3</olNbr>
<soDate>2011-03-13 20:00:00</soDate >
<description>Lbjames is very strong</description>
</orderList>
<orderList>
<olNbr>2</olNbr>
<soDate>2011-03-12 20:00:00</soDate >
<description>Wade run fast</description>
</orderList>
<orderList>
<olNbr>5</olNbr>
<soDate>2011-03-15 20:00:00</soDate >
<description>Yaoming is very high</description>
</orderList>
<orderList>
<olNbr>4</olNbr>
<soDate>2011-03-14 20:00:00</soDate >
<description>Tracy's action is very beautiful</description>
</orderList>
</orderLists>
</root>
</pre>
public static DataTable GetXmlInfoMulti(string xmlPath)
{
DataTable resultDT = new DataTable();
resultDT.Columns.Add("olNbr");
resultDT.Columns.Add("soDate");
resultDT.Columns.Add("description");
string str = string.Empty;
XmlDocument xmlDoc = new XmlDocument();
//加载XML文件
xmlDoc.Load(xmlPath);
XmlElement root = xmlDoc.DocumentElement;
//读取第一层节点
foreach (XmlElement node in root.ChildNodes)
{
//读取第二层节点
foreach (XmlElement chileNode in node.ChildNodes)
{
if (chileNode.Name.Equals("result"))
{
//取得result节点的值
string resultStr = chileNode.InnerText;
//如果不为0,则无数据
if (!resultStr.Equals("0"))
{
return resultDT;
}
}
else if (chileNode.Name.Equals("orderLists"))
{
foreach (XmlElement orderList in chileNode.ChildNodes)
{
DataRow dr = resultDT.NewRow();
foreach (XmlElement floorNode in orderList.ChildNodes)
{
if (floorNode.Name.Equals("olNbr"))
{
dr["olNbr"] = floorNode.InnerText;
}
else if (floorNode.Name.Equals("soDate"))
{
dr["soDate"] = floorNode.InnerText;
}
else if (floorNode.Name.Equals("description"))
{
dr["description"] = floorNode.InnerText;
}
}
resultDT.Rows.Add(dr);
}
}
}
}
return dt;
}