我有一個名爲portfolio的xml文件,我將該位置作爲字符串傳遞。 從元素下的組合文件中讀取文件名列表。在xml文件中,我有一個叫做元素的元素,我需要讀取價格數據中的4個值並將其存儲到字符串列表中。我不知道我是否正確地做了這件事。我不知道我的參數應該用於foreach循環。將xml元素添加到來自XML閱讀器的列表
XML文件:
<priceData>
<file name="ibmx.xml"/>
<file name="msft.xml"/>
<file name="ulti.xml"/>
<file name="goog.xml"/>
</priceData>
這裏是我的功能爲C#
public static void readPortfolio(string filename)
{
XmlTextReader reader = new XmlTextReader(filename);
reader.Read();
List<string> priceDataFile = new List <string>();
foreach(var file in reader) //Don't know what the parameters should be.
{
priceDataFile.Add(reader.Value); //Not sure if I am passing what I want
}
}
你不需要'ToList()'這裏。 – abatishchev 2013-02-18 03:25:21
我編輯了答案並測試了它的工作原理,謝謝abatishchev – MethodMan 2013-02-18 16:01:44