We help IT Professionals succeed at work.
Get Started

How to write to XML files ?

team2005
team2005 asked
on
220 Views
Last Modified: 2010-04-23
Hi!

Include my sub for Reading a XML file.
But dosent know how the sub for writing to the same
XML file, can be done.

Need this ASAP.

So plese sombody give me a sub that writes to this XML file.

Thanks
Sub Main()
        Dim m_xmlr As XmlTextReader
 
        'Create the XML Reader
 
 
        m_xmlr = New XmlTextReader("C:\test.xml")
        'Disable whitespace so that you don't have to read over whitespaces
        ' m_xmlwr = New XmlTextWriter("C:\test.xml")
 
        m_xmlr.WhiteSpaceHandling = WhiteSpaceHandling.NONE
        'read the xml declaration and advance to family tag
 
        m_xmlr.Read()
        'read the family tag
 
        m_xmlr.Read()
        'Load the Loop
 
        While Not m_xmlr.EOF
            'Go to the name tag
 
            m_xmlr.Read()
            'if not start element exit while loop
 
            If Not m_xmlr.IsStartElement() Then
                Exit While
            End If
            'Get the Gender Attribute Value
 
            Dim opsettAttribute As String = m_xmlr.GetAttribute("opsett")
            'Read elements firstname and lastname
 
            m_xmlr.Read()
            'Get the firstName Element Value
            If opsettAttribute = "email" Then
                Dim serverinfo As String = m_xmlr.ReadElementString("server")
                'Get the lastName Element Value
 
                Dim emneinfo As String = m_xmlr.ReadElementString("emne")
                'Write Result to the Console
 
                Dim emailinfo As String = m_xmlr.ReadElementString("email")
 
                Dim malinfo As String = m_xmlr.ReadElementString("mal")
 
                Dim htmteinfo As String = m_xmlr.ReadElementString("htmtekst")
 
                '<email>tor-er-b@online.no</email>
                '<mal>C:\MAL1.HTML</mal>
                '<HTMTE>1</HTMTE>
 
                opsett.serveremail.Text = serverinfo
                opsett.emne.Text = emneinfo
                opsett.Emaila.Text = emailinfo
                opsett.malen.Text = malinfo
                If htmteinfo = "False" Then
                    opsett.CheckBox1.Checked = False
                Else
                    opsett.CheckBox1.Checked = True
                End If
 
 
 
 
 
            End If
 
                If opsettAttribute = "lisens" Then
                    Dim antdagerinfo As Integer = m_xmlr.ReadElementString("dager")
                    'Get the lastName Element Value
 
                    opsett.dager.Text = antdagerinfo
                End If
 
        End While
        'close the reader
 
        m_xmlr.Close()
    End Sub

Open in new window

Comment
Watch Question
IT Pro/Developer
CERTIFIED EXPERT
Top Expert 2008
Commented:
This problem has been solved!
Unlock 1 Answer and 4 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE