How do I read and write data to an XML file?

The following code demonstrates how to read and write to an XML file.

 
<?xml version="1.0" standalone="yes"?> 
  <Document>
    <Customer>
      <Name>Sandeep</Name> 
      <Age>23</Age> 
       <Occupation>Developer</Occupation>
 </Customer>
</Document> 
Imports System
Class WriteToXML
    Shared Sub main()
      Dim dset As New System.Data.DataSet()
      Dim str As String = "Test.xml"
      'Load the XML file in the data set
      dset.ReadXml("Test.xml")
      'Read the XML content on the console
      Console.Write(dset.GetXml)
      'Getting data from the user to be saved into the XML file
      Console.Write("Enter Name : ")
      Dim name, age, occupation As String
      name = Console.ReadLine
      Console.Write("Enter Age : ")
      age = Console.ReadLine
      Console.Write("Enter Occupation : ")
      occupation = Console.ReadLine
      Console.Write(name & age & occupation)
      Dim v(1) As String
      v(0) = fname
      v(1) = age
      v(2)=occupation
      dset.Tables(0).Rows.Add(v)
     dset.WriteXml("Test.xml")
     Console.Write(dset.GetXml)
    End


When you run this code, the data from the XML file will be displayed. Also the data you enter will be updated into the XML file.

Written by Sandeep Mogulla, Webmaster at www.startvbdotnet.com

VB FAQ Index

 
Printer friendly version of the FAQ-VBNET-XML page


Sponsored links

Build IT Knowledge with Current & Trusted Content
Helps Employees Develop & Hone New Technical Programming Skills. Sign Up & Get Full Access.
Check Out IT Certification Preparation Materials
Sign Up With SkillSoft & Get Access to Training Materials for Over 50 Professional Certifications.
Villanova University Six Sigma & IT Certificate Programs
100% Online programs in Six Sigma, IS Security, CISSP Prep, Business Analysis, Proj. Mgmt. and more!
SFTP components for .NET
Add complete SSH and SFTP support to your .NET framework application
3 Months Free - ASP.NET Web Hosting
3 Months Free & No Setup Fees on ASP.NET 3.5/2.0 Hosting on Windows 2008/2003 Servers ? Click Here!

Advertisement



Free Magazine

Free Magazines
eWeek The essential technology information source for builders of e-business.... subscribe now

Newsletter | Submit Content | About | Advertising | Awards | Contact Us | Link to us |
© 1996-2008 Community Networks Ltd All rights reserved. Reproduction in whole or in part, in any form or medium without express written permission is prohibited. Violators of this policy may be subject to legal action. Please read Terms Of Use and Privacy Statement for more information. Development by Synchron Data - .NET development.