How to create xml file?

1)Select the table values from database
2)bind the values to Dataset
3)dataset to xmlDataDocument
4)Give the xml filename and save to current location.
[code]
Imports System.Data
Imports System.Data.SqlClient
Imports System.Xml

Partial Class _Default
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim strConn As String
'create connection to database table.
strConn = "USER=asd;PASSWORD=45646;SERVER=qwer;DATABASE=Emp"
Dim MySQL As String = "Select empno, empname from kk"
Dim MyConn As New SqlClient.SqlConnection(strConn)
Dim ds As DataSet = New DataSet()
Dim Cmd As New SqlClient.SqlDataAdapter(MySQL, MyConn)
'Fill the Table values to Dataset
Cmd.Fill(ds, "Emptbl")
'Bind the dataset values to xmldatadocument
Dim doc As New XmlDataDocument(ds)
doc.Save(MapPath("NewXMLName.xml"))
'This is where we are saving the data in an XML file NewXMLName.xml
End Sub
End Class

[/code]
The output look like
[code]
< NewDataSet >
< Emptbl>
< empno>3< /empno>
< empname>777
< /Emptbl>
< Emptbl>
< empno>344< /empno>
< empname>rrr677 < /empname>
< /Emptbl>
< Emptbl>
< empno>3< /empno>
< empname>ggg'D < /empname>
< /Emptbl>
< Emptbl>
< empno>4< /empno>
< empname>d < /empname>
< /Emptbl>
< Emptbl>
< /Emptbl>
< /NewDataSet>
[/code]

No comments:

Post a Comment

Plz Share your comments...