Programming in VB.NET how to Create and read Xml File with vb.net

preview_player
Показать описание
in this tutoriel we will try to create an xml file and read it.
Рекомендации по теме
Комментарии
Автор

not having sound makes this much harder to learn from

michaelclark
Автор

I tried running the code as written, and like the other individual, could not read the file I created. When I looked at the structure for the created using the source as written, it didn't look like a proper XML structure. When I made the changes to it, it worked. Changes were:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim Writer As New XmlTextWriter("File.xml", System.Text.Encoding.UTF8)

Writer.Formatting = Formatting.Indented
Writer.Indentation = 2

For x = 0 To DataGridView1.Rows.Count - 1
Createnode(DataGridView1.Rows(x).Cells(0).Value, _
DataGridView1.Rows(x).Cells(1).Value, _
DataGridView1.Rows(x).Cells(2).Value, Writer)
Writer.WriteEndElement()
Next

Writer.WriteEndDocument()
Writer.Close()

End Sub
Private Sub Createnode(ByVal SID As String, ByVal SName As String, ByVal SBDay As Date, ByVal writer As XmlTextWriter)


writer.WriteString(SID)
writer.WriteEndElement()

writer.WriteString(SName)
writer.WriteEndElement()

writer.WriteString(SBDay)
writer.WriteEndElement()
End Sub

Despite the issues involved - I want to say "THANK YOU" For creating this video in the first place. It allowed me to learn what steps I needed to go through in order to create the file. If you were to do this again, I would suggest a subroutine for writing the file to a location anywhere on the Hard Drive the user wishes, along with the ability to open up any xml file anywhere on their hard drive, that the users wishes. That I can do on my own, but it might help a beginning neophyte. Now, I'm going to investigate the childnode.count options in addition to the xmlnode.count option you showed in your example. Again, Thank you.

hal
Автор

Hello, please, how can I recover the xml data?
but using the name of the node that you have assigned to it,
not the index of the node location. for example in

instead of saying item(0), specify the node name Student_id
something like item("Student_id").
since when creating the xml it could not necessarily create
the nodes in the same order. I would be very grateful if you help me with that. thank you.

johnnyc.oliveraa.
Автор

HOW DID YOU FIX THE LAST ERROR WITH THE TRIM THING

vietpham
Автор

Hello i know this is a older video but i do have a Question. How can i store the XML file with the visual basic application when i install the application? I mean in the same location file folder as the visual basic program?

DiyintheGhetto
Автор

Thank you for your video. This was really helpful. Although there was one slight problem. When I tried to read the created xml file it would not load. For visual studio community 2017 you have to have the private sub written this way:
Private Sub createnode(ByVal SID As String, ByVal SName As String, ByVal SBDay As String, ByVal writer As XmlTextWriter)


writer.WriteString(SID)
writer.WriteEndElement()

writer.WriteString(SName)
writer.WriteEndElement()

writer.WriteString(SBDay)
writer.WriteEndElement()
writer.WriteEndElement()
End Sub
Aside from that syntax error your code still works.

skippyflatrock
Автор

bro this method only create in xml file no view for xml doc.

alexmaxwell
visit shbcf.ru