Create and Write BirthDay Details in XML

Santosh4u
Posted by Santosh4u under VB.NET category on | Views : 1617
1. Add a Windows Form.
2. Drag one TextBox For Entering Name(txtName)
3. Drag one DateTimePicker For Selecting Date of Birth.(dtpBirthDate)
4. Drag a Button(btnCreateXML)
5.Dim XMLPath As String ="F:\XML Files\BirthDay.xml"

Create a Method Called (createNode)
Private Sub createNode(ByVal Name As String, ByVal BirthDay As String, ByVal writer As XmlTextWriter)
writer.WriteStartElement("BirthDayDetails")
writer.WriteStartElement("Name")
writer.WriteString(Name)
writer.WriteEndElement()
writer.WriteStartElement("BirthDay")
writer.WriteString(BirthDay)
writer.WriteEndElement()
End Sub


Under btnCreateXML Click write this Code.

If txtName.Text = "" Then
MessageBox.Show("Please Enter Name", "BIRTH DAY", MessageBoxButtons.OK, MessageBoxIcon.Information)
Else
Dim writer As New XmlTextWriter(XMLPath, System.Text.Encoding.UTF8)
writer.WriteStartDocument(True)
writer.Formatting = Formatting.Indented
writer.Indentation = 2
writer.WriteStartElement("BirthDays")
createNode(txtName.Text, dtpBirthDate.Text, 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 If

Regards
Santosh

Comments or Responses

Login to post response