/// <summary>
/// 讀取XML
/// </summary>
/// <param name="sFilePath">XML路徑包含文件名</param>
/// <param name="sNode">結點名稱</param>
/// <returns></returns>
private List<string> readXml(string sFilePath, string sNode)
{
List<string> lNodeList = new List<string>();
try
{
if (File.Exists(sFilePath))
{
XPathDocument xpdDocument = new XPathDocument(sFilePath);
XPathNavigator xpnNavigator = xpdDocument.CreateNavigator();
XPathNodeIterator xpiIterator = xpnNavigator.Select(sNode);
while (xpiIterator.MoveNext())
{
lNodeList.Add(xpiIterator.Current.Value);
}
}
}
catch (Exception e)
{
throw e;
}
return lNodeList;
}
/// 讀取XML
/// </summary>
/// <param name="sFilePath">XML路徑包含文件名</param>
/// <param name="sNode">結點名稱</param>
/// <returns></returns>
private List<string> readXml(string sFilePath, string sNode)
{
List<string> lNodeList = new List<string>();
try
{
if (File.Exists(sFilePath))
{
XPathDocument xpdDocument = new XPathDocument(sFilePath);
XPathNavigator xpnNavigator = xpdDocument.CreateNavigator();
XPathNodeIterator xpiIterator = xpnNavigator.Select(sNode);
while (xpiIterator.MoveNext())
{
lNodeList.Add(xpiIterator.Current.Value);
}
}
}
catch (Exception e)
{
throw e;
}
return lNodeList;
}
參數sNode的值有兩種:
一種以"//"表示結點
一種以"@"開頭屬性