what's up? reading xml

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



I'm doing something wrong in the reading of this file. I think the rest will work but it keeps telling me something else is using the file. Nothing is. Any ideas?

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Dim doc As Xml.XmlDocument = New Xml.XmlDocument
Dim reader As New Xml.XmlTextReader("c:\test.xml")
Dim writer As New Xml.XmlTextWriter("c:\test.xml", Nothing)
Try
doc.LoadXml(reader.Read)
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try

Dim account_number As Xml.XmlNodeList = doc.GetElementsByTagName("account_number")
Dim reply_code As Xml.XmlNodeList = doc.GetElementsByTagName("reply_code")
Dim sequence_number As Xml.XmlNodeList = doc.GetElementsByTagName("sequence_number")

MessageBox.Show(account_number(0).InnerText)
MessageBox.Show(reply_code(0).InnerText)
MessageBox.Show(sequence_number(0).InnerText)

writer.Formatting = Xml.Formatting.Indented
doc.Save(writer)
End Sub
.


Quantcast