C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




Create xml file


Posted Date: 22 Aug 2007    Resource Type: Code Snippets    Category: XML

Posted By: Dilip Kumbhar       Member Level: Gold
Rating:     Points: 10



This sample code shows how to generate XML and write to a file.



Imports System.Xml
Imports System.IO
Imports System.Data.SqlClient

Public Function CreateXML() As Boolean
Dim objDataSet As DataSet
Dim intI As Integer
Dim strPath As String
Dim objWriter As XmlTextWriter 'create an instance of the XmlTextWriter object

Try
' location to the XML file to write
strPath = strFilePath & "\XML\" & strSessionID & ".xml"

objWriter = New XmlTextWriter(strPath, System.Text.Encoding.Default)

' start writing the XML document
objWriter.WriteStartDocument()

' write a comment in our XML file
objWriter.WriteComment("Employee")

' starting with the root element i.e. "movies"
objWriter.WriteStartElement("Menu")

'Create dataset as per your requirement.Here xml for Employee is created.The elements are Empno,Emp_name and salary

'Set data to XML tags
If objDataSet.Tables(0).Rows.Count > 0 Then
For intI = 0 To objDataSet.Tables(0).Rows.Count - 1
objWriter.WriteStartElement("Employee") ' output the "Employee" element
objWriter.WriteElementString("EmpNo", objDataSet.Tables(0).Rows(intI).Item("EmpNo").ToString)
objWriter.WriteElementString("Name", objDataSet.Tables(0).Rows(intI).Item("Emp_Name").ToString)
objWriter.WriteElementString("Salary", objDataSet.Tables(0).Rows(intI).Item("Salary"))
objWriter.WriteEndElement() ' close "Employee" element
Next
End If

' end the "Menu" element
objWriter.WriteEndElement()

' flush and write XML data to the file
objWriter.Flush()

Return True
Catch ex As Exception
Return False
Finally
' clear up memory
objWriter.Close()
objWriter = Nothing
objDataSet = Nothing
End Try
End Function






Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Reading an XML File
Previous Resource: Read xml using javascript.
Return to Discussion Resource Index
Post New Resource
Category: XML


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design

efax

Contact Us    Privacy Policy    Terms Of Use