Click here to Skip to main content
15,905,587 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to read all xml nodes and display it in Datagridview...
.
.
Thanks in adv..

What I have tried:

C#
XmlReader xmlFile;
xmlFile = XmlReader.Create("G:\\Campaign_20062400.xml", new XmlReaderSettings());
          DataSet ds = new DataSet();
          ds.ReadXml(xmlFile);
          dataGridView1.DataSource = ds.Tables[0];





here is my xml file..


XML
<CAMPAIGN_00>

<DIP_1>
<stSetpoints>
<iInputCatsPerTooling>8</iInputCatsPerTooling>
<rInputSPSubstrateWeight>
<fMin>126</fMin>
<fMax>154</fMax>
<fTgt>140</fTgt>
</rInputSPSubstrateWeight>
<rInputSPWetUptakeWeight>
<fMin>8.1000004</fMin>
<fMax>9.8999996</fMax>
<fTgt>9</fTgt>
</rInputSPWetUptakeWeight>
<rCalculatedSPWetUptakePerc>
<fMin>90</fMin>
<fMax>109.99999</fMax>
<fTgt>100</fTgt>
</rCalculatedSPWetUptakePerc>
</stSetpoints>
<sDipStatus>GOOD</sDipStatus>
<rSubstrateWeight>1144</rSubstrateWeight>
<rWetScale1>1217.9</rWetScale1>
<rWetUptakeWeight>73.900024</rWetUptakeWeight>
<rWetUptakePercent>102.63892</rWetUptakePercent>
</DIP_1>

<DIP_2>
<stSetpoints>
<iInputCatsPerTooling>8</iInputCatsPerTooling>
<rInputSPSubstrateWeight>
<fMin>126</fMin>
<fMax>154</fMax>
<fTgt>140</fTgt>
</rInputSPSubstrateWeight>
<rInputSPWetUptakeWeight>
<fMin>8.1000004</fMin>
<fMax>9.8999996</fMax>
<fTgt>9</fTgt>
</rInputSPWetUptakeWeight>
<rCalculatedSPWetUptakePerc>
<fMin>90</fMin>
<fMax>109.99999</fMax>
<fTgt>100</fTgt>
</rCalculatedSPWetUptakePerc>
</stSetpoints>
<sDipStatus>GOOD</sDipStatus>
<rSubstrateWeight>1143.4</rSubstrateWeight>
<rWetScale1>1222.1</rWetScale1>
<rWetUptakeWeight>78.699951</rWetUptakeWeight><rWetUptakePercent>109.30549</rWetUptakePercent>
</DIP_2>
</CAMPAIGN_00>





it not work as expected..suggest any idea..
Posted
Updated 19-Aug-20 4:06am

Quote:
To read both data and schema, use one of the ReadXML overloads that includes the mode parameter, and set its value to ReadSchema.

Based on what you are trying, you don't need to use XMLReader to read the file content. Instead use the file directly to dataset ReadXML method.

It should work with:
DataSet dataSet = new DataSet();  
dataSet.ReadXml(@"G:\Campaign_20062400.xml");  
dataGridView1.DataSource = dataSet.Tables[0];  

Reference: DataSet.ReadXml Method (System.Data) | Microsoft Docs[^]


Here are few more references that can help you:
Read, Parse and Import XML file in Windows DataGridView using C# and VB.Net[^]
Read XML data into a dataset - Visual Studio | Microsoft Docs[^]
 
Share this answer
 
Comments
Sam_gaik 19-Aug-20 10:31am    
it only read <dip_1>..
need to read all nodes
Sandeep Mewara 19-Aug-20 11:16am    
Reads all. It's the table index here that drives it. You can use accordingly

dataGridView1.DataSource = dataSet.Tables[0];

for dip_2, dataGridView1.DataSource = dataSet.Tables[1];
Sam_gaik 23-Aug-20 8:25am    
It not work...
Sandeep Mewara 23-Aug-20 8:33am    
Use DEBUGGER, see whats in dataset while assigning it to grid. You should see two tables in it. Pick the one you want to bind.

Sam_gaik 23-Aug-20 9:35am    
and how to assign both table..?
It works fine for me:
GOOD	1144	1217.9	73.900024	102.63892

But ... a quick look at the dataset says there are six tables in there, so it's quite possible that Tables[0] does not contain the data you are looking for...
 
Share this answer
 
Comments
Sam_gaik 23-Aug-20 8:27am    
It show only..<dip_1>
Other data not showing.. why?..pls help
OriginalGriff 23-Aug-20 9:00am    
As I said: there are 6 tables in there. Use the debugger to look at them and see if you can spot the data you are looking for.
Sam_gaik 23-Aug-20 9:34am    
And how to display all table..
OriginalGriff 23-Aug-20 10:31am    
Use the debugger - you can look at any memory with that!
Sam_gaik 26-Aug-20 6:36am    
It show only single table .. need all <dip> in single grid...pls help...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900