July 01, 2003
Parsing XML Files in .NET Using C#
Parsing XML Files in .NET Using C#
Listing 9 Parsing XML using DataSet
using System;
using System.Xml;
using System.Data;
using CommonLib; // Suite class definition
using InfoLib; // DisplayInfo() method
namespace Run
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
DataSet ds = new DataSet();
ds.ReadXml("..\\..\\..\\..\\testCases.xml");
InfoLib.DataSetInfo.DisplayInfo(ds); // show table, column, relation names
CommonLib.Suite s = new CommonLib.Suite();
foreach (DataRow row in ds.Tables["testcase"].Rows)
{
CommonLib.TestCase tc = new CommonLib.TestCase();
tc.id = row["id"].ToString();
tc.kind = row["kind"].ToString();
tc.expected = row["expected"].ToString();
DataRow[] children = row.GetChildRows("testcase_inputs"); // relation name
tc.arg1 = (children[0]["arg1"]).ToString(); // there is only 1 row in children
tc.arg2 = (children[0]["arg2"]).ToString();
s.items.Add(tc);
}
s.Display();
} // Main()
} // class Class1
} // ns
Previous Page |
1
|
2
|
3
|
4
|
5
|
6
|
7
|
8
|
9
|
10
|
11
|
12
|
13
|
14
|
15
|
16