Click here to Skip to main content
15,913,183 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hey

I have made a program that opens,views ,edits and saves to a xml

But I have a problem

I notice that I have some fields in my XML document that have child nodes as the same Parent nodes.

Heres a sample of what Iam talking about

<root>
<ai_ratio>
 <ai_ratio>0.35</ai_ratio>
 <discipline_id>27</discipline_id>
 <id>1</id>
 <season_id>1</season_id>
 <star_level>0</star_level>
 </ai_ratio>
 <ai_ratio>
 <ai_ratio>0.05</ai_ratio>
 <discipline_id>28</discipline_id>
 <id>2</id>
 <season_id>1</season_id>
 <star_level>0</star_level>
 </ai_ratio>
 <ai_ratio>
 <ai_ratio>0.35</ai_ratio>
 <discipline_id>29</discipline_id>
 <id>3</id>
 <season_id>1</season_id>
 <star_level>0</star_level>
 </ai_ratio>
</root>






because of these child nodes the data view does not come up right.It doesn't apply the child nod ai_ratio to a column in the data grid view like it should and it generates a empty row because in thinks its a new lot of data .

Here is my code Iam using to render the datagrid .Its probably not the best method :( but it is working



Public Class Form1
 Dim ds As New DataSet("Dataset1")

 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
 Dim table As String
 table = ListBox1.Text

 Dim filePath As String
 OpenFileDialog1.ShowDialog()

 filePath = OpenFileDialog1.FileName
 ds.ReadXml(filePath)
 

 With (DataGridView1)
  .DataSource = ds
  'define what table is used 
  .DataMember = table


 End With
 End Sub


 Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
 
 Try
  DataGridView1.DataMember = ListBox1.Text
 Catch ex As Exception

 End Try
 End Sub

 Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
 SaveFileDialog1.ShowDialog()

 Dim savepath1 As String
 savepath1 = SaveFileDialog1.FileName
 ds.WriteXml(savepath1)
 End Sub
End Class


Heres a pic of the app
<<img src="http://img12.imageshack.us/img12/4452/82669986.jpg" border="0" alt="" /> Uploaded with ImageShack.us
Uploaded with ImageShack.us>

So what do I have to do to filter these childnodes from the dataset .New method or is there so code which I can include to deal with these child nodes .

Cheers
Posted
Comments
Maciej Los 4-Jul-11 12:17pm    
Change <ai_ratio> childnote to <element>, <value>, <data> or any other name.

1 solution

There is no direct way to achieve it, you can read every child node one by one and create datatable and bind it to grid.
 
Share this answer
 

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