希望有人可以用這個指向正確的方向。迭代通過數據集獲取子行
我想通過一個XML文件進行迭代,並得到在XML文件中的每個「表」,並得到各子行等
我能得到不屬於子行等就好行。
這裏是xml結構的一個例子。
<items>
<item>
<id>1</id>
<row1>abc</row1>
<row2>abc</row2>
<needthis>
<first>John</first>
<last>John</last>
</needthis>
</item>
</items>
這就是我目前使用的。
foreach (DataTable table in ds.Tables)
{
foreach (DataRow row in table.Rows)
{
foreach (DataColumn column in table.Columns)
{
object item = row["id"];
object item2 = row["row1"];
//Just to see what is returning
System.Windows.Forms.MessageBox.Show(item.ToString());
System.Windows.Forms.MessageBox.Show(item2.ToString());
}
}
}
我需要什麼來獲得needthis表的第一行和最後一行?
你試過[DataRow.GetChildRows](http://msdn.microsoft.com/en-us/library/system.data.datarow.getchildrows(v = vs.110).aspx)? –
您是否有使用數據集的原因,而不僅僅是解析XML?這似乎是一個更容易維護的方法。 –
@MatthewHaugen我是一切爲了更有意義和更容易。這是我第一次必須使用C#讀取/解析和xml文件,而且是我遇到的第一個例子,似乎工作,直到我需要子行等。 – Bowenac