Monday, January 22, 2007

Creating a simple XML file in VB.net

The below is code for creating the XML file in VB.net.
copy and paste the code in on module and see how its work...
----------------------------------------------------------------
Private sub CreateXMLFile (strRootDirectoryName as string)

Dim mywriter As System.Xml.XmlTextWriter
mywriter = New System.Xml.XmlTextWriter(strRootDirectoryName & "AddressType.xml", Nothing)
mywriter.WriteStartDocument()
mywriter.WriteStartElement("AddressType")
mywriter.WriteElementString("Company", strCompany)
mywriter.WriteElementString("Address1", strAddress1)
mywriter.WriteElementString("Address2", strAddress1)
mywriter.WriteElementString("City", strCity)
mywriter.WriteElementString("State", strState)
mywriter.WriteElementString("Country", strCountry)
mywriter.WriteElementString("Zip", strZip)
mywriter.WriteElementString("Fax", strFax)
mywriter.WriteElementString("Phone", strPhone)
mywriter.WriteElementString("Email", strEmail)
mywriter.WriteEndDocument()
mywriter.Flush()
mywriter.Close()

End Sub
----------------------------------------------------------------
Hope this is more helpfull for XML beginners.

No comments: