By submitting your personal information, you agree to receive emails regarding relevant products and special offers from TechTarget and its partners. You also agree that your personal information may be transferred and processed in the United States, and that you have read and agree to the Terms of Use and the Privacy Policy.

ADO provides a rich infrastructure for interacting with a wide variety of data, including XML. With DataSets we can now read and write to an XML file with ease.

The following code sample demonstrates how to read and write to an XML file. We are going to read and write an XML file with the details as under:

Class : xml.vbImports System
Class WriteXML
Shared Sub main()
Dim objDataSet As New System.Data.DataSet()
Dim strVirtualPath As String = "t.xml"
'Load the XML file in the data set
objDataSet.ReadXml("xmlfile.xml")
'Read the XML content on the console
Console.Write(objDataSet.GetXml)
'Get data from the user to be saved in the XML file
Console.Write("Enter Name : ")
Dim fname, age As String
fname = Console.ReadLine
Console.Write("Enter Age : ")
age = Console.ReadLine
Console.Write(fname & age)
Dim v(1) As String
v(0) = fname
v(1) = age
'Add the data to the data set
objDataSet.Tables(0).Rows.Add(v)
'Write to updated data back to the XMl file
objDataSet.WriteXml("xmlfile.xml")
Console.Write(objDataSet.GetXml)
End Sub
End Class

0 comments

E-Mail

Username / Password

Password

By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy