Saving the text of named VB.NET controls to XML

How to save the text of named VB.NET controls to an XML file

VB.NET

Protected Sub SaveXML_2()

  Dim settings As New XmlWriterSettings()
  settings.Indent = True

  Dim XmlWrt As XmlWriter = XmlWriter.Create("C:\SaveXML_002.xml", settings)

  With XmlWrt
    
    .WriteStartDocument()
    .WriteStartElement("Cells")

      .WriteStartElement("customercontact")
      .WriteString(customercontact.Text)
      .WriteEndElement()

      .WriteStartElement("contacttitle")
      .WriteString(contacttitle.Text)
      .WriteEndElement()

    .WriteEndElement()
    .WriteEndDocument()
    .Close()

  End With
End Sub

XML (output)

<Cells>
  <customercontact>Adam Watson</customercontact>
  <contacttitle>Scientist</contacttitle>
</Cells>
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s