Hello all, I have been lurking for a few months around the forums and coding quietly in a dark corner, but recently I have hit a problem I just can't seem to solve.
I am writing an application in VB.NET, and attempting to read in configuration information from a .XML file. I read through the MSDN samples and it seemed extremely straightforward, but when I tried to make it work I ran into problems. I took a small code sample from these forums to read in the value. (slightly modified)
----------------------------------------------------------------
Function GetValue(ByVal key as String) As String
Try
Dim xmlDoc As New XmlDocument()
xmlDoc.Load("C:\test.xml")
Return xmlDoc.SelectSingleNode("//" & key).InnerText
Catch ex As Exception("Error reading file: test.xml", ex)
End Try
End Function
----------------------------------------------------------------
The first time I tried it, the code returned a value, and everything seemed to work fine. I came back into work the next day, and as things often go... I changed something and it refuses to work now.
I have tried using the MSDN samples for the .XML file to make sure my formatting on the file is correct, I have tried using SelectSingleNode, and SelectNodes, wrote different code several times, but both methods return a null value. I can assign a variable to the root and access the file:
-----------------------------------------------------------------
Dim doc As XmlDocument = New XmlDocument()
doc.Load("C:\test.xml")
Dim root As XmlNode = doc.DocumentElement
msgbox(root.FirstChild.InnerText)
-----------------------------------------------------------------
This tells me that I have accessed the .XML file, I can see the data inside it, and I can manuever the values. When I try to select a specific node using SelectSingleNode/SelectNodes however, I get a null value regardless of what I put in the XPath. I have tried everything I can think of at this point... and I'm basically out of ideas. I appreciate any ideas you have!
Aaron