get data from xmlDataDocument.DataSet.Tables(...)

Hello togehter,

I have the following structure in my xml file:

<xmlData>
   <test>
      <information>
         <id/>
        <text/>
      </information>
     <information>
         <id/>
        <text/>
      </information>
  </test>
  <test>
      <information>
         <id/>
        <text/>
      </information>
     <information>
         <id/>
        <text/>
      </information>
  </test>
</xmlData>

I am using xmlDocument.DataSet.Tables to get the data from my xml file.
xmlTable as DataTable = xmlDocument.DataSet.Tables(information)
At the moment I want to get all data from information tag. The problem is that I always get the content from the first information element.

So  my question is how can I get all the information tags?
GaialaAsked:
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.

anna_arunCommented:
This code is in c#

DataSet ds = new DataSet();
ds.ReadXml(MapPath("XMLFile.xml"));
DataTable xmlTable = ds.Tables["information"];

now xmlTable[i]["id"] or xmlTable[i]["text"] will give you your desired data, where "i" will be your row number.
You can get the total number of rows by using xmlTable.Rows.Count.

WIth your code it might be possible that there would have been some error while loading teh xml file into xmldocument.

I tried my code with the exact xml file you have provided and it works
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
GaialaAuthor Commented:
ok.
this data I willl bind to a gridview.
the requirement is to see the information of a test element in a gridview. --> each test element the information content in one gridview.
0
anna_arunCommented:
if you will bind the datatable xmlTable to a gridview and set its sutogeneratecolumn property to true, all the data under "information" nodes will come in separate rows in the gridview.
You wont have to do anything. you will see 4 rows of data in your gridview.

If I misunderstood your question, could you plaese elaborate more?
0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

GaialaAuthor Commented:
ok I try. The requirement is to display for each test element a gridview. That means that for the above example I will get 2 gridviews and both gridviews have to lines.
0
anna_arunCommented:
no you will get one gridview with 4 rows
the reason being the datatabkle selected is "information". From the XML file, the datatable will pick 4 rows of information node

if we would have been chosen table "test", then the grid would be returning two rows

BTW, are you trying to display a nested grid or hierarchical grid.
0
GaialaAuthor Commented:
yes I know that I will get a gridview with 4 rows. But my questions is how to get 2 gridviews which contains ONLY the information content.

the application displays:
First GridView
informationID   Text
01        some Text
02       some Text

Second GridView
informationID    Text
01           some Text of the second GridView
02          some Text of the second GridView
for example an enhancement
<xmlData>
   <id/>
   <test>
  <id/>
      <information>
         <id>01<id/>
        <text>some text<text/>
      </information>
     <information>
         <id>02<id/>
        <text>some text<text/>
      </information>
  </test>
  <test>
  <id/>
      <information>
          <id>01<id/>
       <text>some Text of the second GridView<text/>
      </information>
     <information>
          <id>02<id/>
        <text>some Text of the second GridView<text/>
      </information>
  </test>
</xmlData>

Open in new window

0
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
.NET Programming

From novice to tech pro — start learning today.