//XML格式
<NewDataSet>
<DeliverySchedule>
<Item>1</Item>
<Qty>1000</Qty>
<Unit>PCS</Unit>
<CRDDate>07/23/2014</CRDDate>
</DeliverySchedule>
<DeliverySchedule>
<Item>2</Item>
<Qty>5000</Qty>
<Unit>PCS</Unit>
<CRDDate>07/28/2014</CRDDate>
</DeliverySchedule>
</NewDataSet>
------------------------
string strXML = "<NewDataSet><DeliverySchedule><Item>1</Item><Qty>1000</Qty><Unit>PCS</Unit><CRDDate>07/23/2014</CRDDate></DeliverySchedule><DeliverySchedule><Item>2</Item><Qty>5000</Qty><Unit>PCS</Unit><CRDDate>07/28/2014</CRDDate></DeliverySchedule><DeliverySchedule><Item>3</Item><Qty>24000</Qty><Unit>PCS</Unit><CRDDate>07/30/2014</CRDDate></DeliverySchedule></NewDataSet>";
//建立 XmlDocument
XmlDocument xmlDoc = new XmlDocument();
//讀取 Xml
xmlDoc.LoadXml(strXML);
//擷取節點
XmlNodeList xmlNodeList = xmlDoc.SelectNodes("/NewDataSet/DeliverySchedule");
//擷取將該節點下的 子節點的值
foreach (XmlNode node in xmlNodeList)
{
//方法一: node.ChildNodes[0].InnerText;
//string strItem = node.ChildNodes[0].InnerText;
//string strQty = node.ChildNodes[1].InnerText;
//string strUnit = node.ChildNodes[2].InnerText;
//string strCRDDate = node.ChildNodes[3].InnerText;
//方法二: node.SelectSingleNode("節點名稱").InnerText;
string strItem = node.SelectSingleNode("Item").InnerText;
string strQty = node.SelectSingleNode("Qty").InnerText;
string strUnit = node.SelectSingleNode("Unit").InnerText;
string strCRDDate = node.SelectSingleNode("CRDDate").InnerText;
}
留言列表