?
Solved

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

Posted on 2008-01-30
6
Medium Priority
?
567 Views
Last Modified: 2010-05-19
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?
0
Comment
Question by:Gaiala
  • 3
  • 3
6 Comments
 
LVL 1

Accepted Solution

by:
anna_arun earned 1200 total points
ID: 20778201
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
 

Author Comment

by:Gaiala
ID: 20778504
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
 
LVL 1

Expert Comment

by:anna_arun
ID: 20778674
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
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 

Author Comment

by:Gaiala
ID: 20778915
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
 
LVL 1

Expert Comment

by:anna_arun
ID: 20779123
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
 

Author Comment

by:Gaiala
ID: 20779268
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

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Enter Foreign and Special Characters Enter characters you can't find on a keyboard using its ASCII code ... and learn how to make a handy reference for yourself using Excel ~ Use these codes in any Windows application! ... whether it is a Micr…
Stellar Phoenix SQL Database Repair software easily fixes the suspect mode issue of SQL Server database. It is a simple process to bring the database from suspect mode to normal mode. Check out the video and fix the SQL database suspect mode problem.

588 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question