我正在尝试使用一种不那么传统的方法来编写一个xml文件,只是对于那些想知道那些长篇故事的人来说,为什么我这样做。真正的问题是,我似乎无法让Tag命名为将其值写入生成的XML文件,我无法理解为什么......有人可以帮助我...
代码如下......
Private Sub SaveToolStripMenuItem2_Click(sender As Object, e As EventArgs) Handles SaveToolStripMenuItem2.Click
'define a save dialog
Dim save_file As New SaveFileDialog
'give its extension...
save_file.RestoreDirectory = True
save_file.InitialDirectory = My.Application.Info.DirectoryPath & " \ LIBRARY"
save_file.Filter = "xml files (*.xml)|*.xml|All files (*.*)|*.*"
save_file.FilterIndex = 1
''create a datatable
'Dim my_datatable As New DataTable
'if ok click
If save_file.ShowDialog() = DialogResult.OK Then
Using writer As New IO.StreamWriter(save_file.FileName)
writer.WriteLine("<COMPELATION>")
For Each row As DataGridViewRow In Me.DataGridView1.Rows
If Not row.IsNewRow Then
writer.WriteLine(String.Format(vbCrLf & vbTab & "<Data>" & vbCrLf & vbTab & vbTab & "<DEF>{0}</DEF>" & vbCrLf & vbTab & vbTab & "<HGT>{1}</HGT>" & vbCrLf & vbTab & vbTab & "<LEN>{2}</LEN>" & vbCrLf & vbTab & vbTab & "<WDT>{3}</WDT>" & vbCrLf & vbTab & vbTab & "<THK>{4}</THK>" & vbCrLf & vbTab & vbTab & "<AN1>{5}</AN1>" & vbCrLf & vbTab & vbTab & "<AN2>{6}</AN2>" & vbCrLf & vbTab & vbTab & "<MAT>{7}</MAT>" & vbCrLf & vbTab & "</Data>",
row.Cells(0).Value,
row.Cells(1).Value,
row.Cells(2).Value,
row.Cells(3).Value,
row.Cells(4).Value,
row.Cells(5).Value,
row.Cells(6).Value,
row.Cells(7).Value))
End If
Next
writer.WriteLine("</COMPELATION>")
writer.Close()
End Using
Dim result1 As DialogResult = MessageBox.Show("Would you like to use this file as the default library?", "Information", MessageBoxButtons.YesNo)
If result1 = DialogResult.Yes Then
'Set the new file as the default XML...
My.Settings.DEFAULTXML = save_file.FileName
'Reload and bind the data source...
Me.Refresh()
Else
End If
End If
End Sub