VB.Net-Informations.com
   Home      .Net Framework      VB.NET      C#                                                                      About


  How to create an XML file in VB.NET

XML is a platform independent language, so the information formatted in XML can be used in any other platforms (Operating Systems). If we create an XML file in one platform it can be used in other platforms also.

For creating a new XML file in VB.NET, we are using XmlTextWriter class . The class takes FileName and Encoding as argument. Also we are here passing formating details . The following source code creating an XML file product.xml and add four rows in the file.

         VB.NET Source Code Download           Print Source Code
         How to create an XML file in VB.NET - Download
        
C# Tutorial

Imports System.Xml
Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim writer As New XmlTextWriter("product.xml", System.Text.Encoding.UTF8)
        writer.WriteStartDocument(True)
        writer.Formatting = Formatting.Indented
        writer.Indentation = 2
        writer.WriteStartElement("Table")
        createNode(1, "Product 1", "1000", writer)
        createNode(2, "Product 2", "2000", writer)
        createNode(3, "Product 3", "3000", writer)
        createNode(4, "Product 4", "4000", writer)
        writer.WriteEndElement()
        writer.WriteEndDocument()
        writer.Close()
    End Sub
    Private Sub createNode(ByVal pID As String, ByVal pName As String, ByVal pPrice As String, ByVal writer As XmlTextWriter)
        writer.WriteStartElement("Product")
        writer.WriteStartElement("Product_id")
        writer.WriteString(pID)
        writer.WriteEndElement()
        writer.WriteStartElement("Product_name")
        writer.WriteString(pName)
        writer.WriteEndElement()
        writer.WriteStartElement("Product_price")
        writer.WriteString(pPrice)
        writer.WriteEndElement()
        writer.WriteEndElement()
    End Sub
End Class

Output of the above source code :
product.xnl



VB.NET XML Related Contents
*     How to XML in VB.NET
*     How to open and read an XML file in VB.NET
*     How to create an XML file in VB.NET using Dataset
*     How to open and read an XML file in VB.NET using Dataset
*     How to create an XML file from SQL in VB.NET
*     How to search in an XML file
*     How to filter data in an XML file
*     How to insert data from xml to database
*     How to create an Excel file from XML
*     How to create an XML file from Excel
*     How to xml to DataGridView
*     How to create a TreevView from XML
*     How to create Crystal Reports from XML
*     How to serialization in xml
*     How to serialize a .Net Object to XML
*     How to de-serialize from an XML file to .Net Object


   Home      VB.NET      C#
VB.Net Related Topics
*     Microsoft .Net Framework Tutorials
*     VB.NET Language Basics Tutorials
*     VB.NET Program Flow Control Tutorials
*     VB.NET Collections Tutorials
*     VB.NET String Tutorials
*     VB.NET Files Tutorials
*     VB.NET Excel 2007 Tutorials
*     VB.NET Crystal Reports Tutorials
*     VB.NET Communications Tutorial
*     VB.NET ADO.NET Tutorial
*     ADO.NET Data Providers help and Tutorial
*     VB.NET ADO.NET Dataset Tutorial
*     ADO.NET DataAdapter and Dataset
*     VB.NET ADO.NET DataView Tutorial
*     VB.NET Remoting Tutorial
*     VB.NET XML Tutorial
*     VB.NET DataGridView Tutorial
   Home      VB.NET      C#
More Source Code :   
Mail to :  feedback@net-informations.com
  |  Home   |  VB.NET   |  C#   |  SiteMap   |  Terms of Use   |  About   |
net-informations.com (C) 2010
All Rights Reserved. All other trademarks are property of their respective owners.