[英]C# WinForms Read XML File - Only Specific Nodes
我有一個XML文件:
<Database>
<SMS>
<Number>+447761692278</Number>
<DateTime>2009-07-27T15:20:32</DateTime>
<Message>Yes</Message>
<FollowedUpBy>Unassigned</FollowedUpBy>
<Outcome></Outcome>
<Quantity>0</Quantity>
<Points>0</Points>
</SMS>
<SMS>
<Number>+447706583066</Number>
<DateTime>2009-07-27T15:19:16</DateTime>
<Message>STOP</Message>
<FollowedUpBy>Unassigned</FollowedUpBy>
<Outcome></Outcome>
<Quantity>0</Quantity>
<Points>0</Points>
</SMS>
</Database>
目前,我使用以下命令將其讀入到datagridview中:
public void Read()
{
DataSet ds = new DataSet("SMS DataSet");
XmlDataDocument xmlDatadoc = new XmlDataDocument();
xmlDatadoc.DataSet.ReadXml(@"C:\Documents and Settings\Administrator\Desktop\RecSmsDB.xml");
ds = xmlDatadoc.DataSet;
this.dataGridView1.DataSource = ds;
this.dataGridView1.DataMember = "SMS";
this.dataGridView1.Sort(dataGridView1.Columns["DateTime"], ListSortDirection.Descending);
}
我希望只能讀取具有特定DateTime的xml對象。 有人知道這樣做的方法嗎? 目前,我已經嘗試了命名空間中包含的各種方法,但均無濟於事。
非常感謝您的幫助,
問候。
***編輯:我希望能夠動態更改運行時顯示的數據。
不是我能想到的。 但是,您可以將所有數據讀取到DataSet中,然后創建一個用於過濾SMS表格的DataView,並將您的網格綁定到該表格而不是DataTable。
如果將DataSet附加到BindingSource並將該BindingSource附加到網格怎么辦? BindingSource具有Filter屬性,您可以在其中輸入類似SQL的表達式。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.