Getting to Desired XML data in DataSet

I have the following XML:
<root>
<level name="hello">
<term>One</term>
<term>two</term>
</level>
<level name='goodbye>
<term>Three</term>
<term>Four</term>
</level>
</root>

This is loaded into a DataSet... now how to I access only One and Two, then only Three and Four?

dsDataSet.LoadXml(xml);
dtDataTable = dsDataSet.Tables[1];

... here is where I get stuck.

I can get to the entire list of term elements using Tables[2], but I just want the subsets. Once I have them I want to foreach through them.

Thanks
jkelly061597Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Chester_M_RagelCommented:
Try like this, test will be the ones which you are looking for...

foreach(DataRow row in dtDataTable.Rows)
{
        string test = row[0].ToString();
}
0
jkelly061597Author Commented:
test now = "0"... Not the XML of elements One and Two...
0
Chester_M_RagelCommented:
It is strange, I did a test with this,

<root>
<level name="hello">
<term>One</term>
<term>two</term>
</level>
<level name="goodbye">
<term>Three</term>
<term>Four</term>
</level>
</root>

and

DataSet ds = new DataSet();
ds.ReadXml(@"c:\a.xml");
DataTable dtDataTable = ds.Tables[1];
string test = "";
foreach(DataRow row in dtDataTable.Rows)
{
       test = row[0].ToString();
}

and the result was one,two,three and four!
0
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

jkelly061597Author Commented:
Okay, I concurr. However what I want two sets of data One, Two and Three, Four.

Since One and Two are under "Hello" and Three and Four are under "Goodbye" I want to process them differently...
0
jkelly061597Author Commented:
I solved the problem by placing this XML into an XmlDocument (System.Xml) and using an xPath query for the desired node & children.

Example xPath to retrieve the first level node:
/root/level[@name='hello']

From here you have an XmlNode and you can select the child nodes to get at each term.
0
ee_ai_constructCommented:
Question answered by asker or dialog valuable.
Closed, 200 points refunded.
ee_ai_construct (replacement part #xm34)
Community Support Admin
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.