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

Reading XML Nodes into correspondingly named VB.NET Textboxes

Question : How do I read XML node-values (from an XML file) into correspondingly named VB.NET Textbox controls ?

.xml



    123456789
    987654321
    Programming Widgets Inc.
    Ben Franklin
    Lead Programmer
    ben.franklin@pwi.com
   

.aspx.vb

Protected Sub Page_Load() Handles Me.Load

    Dim settings As New XmlReaderSettings()
    settings.ConformanceLevel = ConformanceLevel.Fragment
    settings.IgnoreWhitespace = True
    settings.IgnoreComments = True

    Dim XML_Reader As XmlReader = XmlReader.Create(C:\XML\basic-information.xml, settings)

    XML_Reader.MoveToContent()

    While XML_Reader.Read()

      If XML_Reader.NodeType = XmlNodeType.Element Then

        Dim NodeName As String = XML_Reader.Name

        XML_Reader.Read()
        Dim NodeValue As String = XML_Reader.Value

        Dim PageControl As RadTextBox = RadMultiPage1.FindControl(NodeName)

        If (Not PageControl Is Nothing) Then
          PageControl.Text = NodeValue
        Else
          ' "Control not found" - error message
        End If

      End If

      End While
      XML_Reader.Close()

End Sub