I am trying to create a function that uses XmlReader to get a single value from an xml file. This function is passed two parameters:
chartName: which is the name of the ChartName attribute for the <Chart> node that you are looking for.
elementName: which is the name of the element you are looking for.
For example if I wanted to get the value of goal from the Astenteeism chart I would do
Dim myString As String = getStuff("Goal","Absenteeism")
This should return 0.5 (see xml below)
But the problem is that it will return 0.8 For some reason it is grabbing the goal tag value from whatever goal tag is first. I'm not sure why?
I tried to give as much info as I could let me know if any details are confusing. Thanks for your help.
here's my code.
Private Function getStuff(ByVal chartName As String, ByVal elementName As String) As String
Dim settings As New XmlReaderSettings
settings.IgnoreComments = True
settings.IgnoreWhitespace = True
Dim myXMLFile As XmlReader = XmlReader.Create("C:\Documents and Settings\honeymoon\My Documents\2010_Config.xml", settings)
Dim locationNameString As String
locationNameString = Nothing
locationNameString = myXMLFile.ReadElementContentAsString
Here's the xml file.
<Chart ChartName = "Operational Availability">
<Chart ChartName = "Absenteeism">