2010-07-19 57 views
1

我想找到一些工作的例子來學習數據集與XML的奇蹟。我使用這個xml數據的這個example。我想通過所有CD節點搜索TITLE值。在數據集中搜索和檢索xml?

DataSet dsXml = new DataSet();
dsXml.ReadXml(msXml);

回答

0

這是一個非常簡單的C#代碼將打印所有的 「TITLE」 中提供的XML:

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Data; 
using System.Xml; 
using System.IO; 

namespace ConsoleApplication1 
{ 
class Program 
{ 
    static void Main(string[] args) 
    { 
     DataSet dsXml = new DataSet(); 
     dsXml.ReadXml("http://www.w3schools.com/xml/cd_catalog.xml"); 

     for (int i = 0; i < dsXml.Tables.Count; i++) 
     { 
      Console.WriteLine("Table Name: " + dsXml.Tables[i].TableName); 
      int j = 1; 
      foreach (DataRow myRow in dsXml.Tables[i].Rows) 
      { 
       Console.Write("[" + j++ + "]"); 
       foreach (DataColumn myColumn in dsXml.Tables[i].Columns) 
       { 
        if (myColumn.ColumnName.Equals("TITLE")) 
         Console.Write("[" + myRow[myColumn] + "]"); 
       } 
       Console.WriteLine(""); 
      } 
     } 
    } 
} 
}