Acquiring multiple attributes from .xml file in c#

atsandran31

New Member
I have an .xml file with the structure below. I am wanting to acquire the attribute value, 0.05 and so on, for specific EndPointChannelID's. I am currently able to get the value but it is for every EndPointChannelID instead of for a desired one. Another twist is that the readings are not always going to be 6. How can I achieve only storing the values from the desired EndPointChannelID? Any suggestions will be greatly appreciated!\[code\] <Channel ReadingsInPulse="false"> <ChannelID EndPointChannelID="5154131" /> <ContiguousIntervalSets> <ContiguousIntervalSet NumberOfReadings="6"> <TimePeriod EndRead="11386.22" EndTime="2013-01-15T02:00:00Z"/> <Readings> <Reading Value="http://stackoverflow.com/questions/15908191/0.05" /> <Reading Value="http://stackoverflow.com/questions/15908191/0.04" /> <Reading Value="http://stackoverflow.com/questions/15908191/0.05" /> <Reading Value="http://stackoverflow.com/questions/15908191/0.06" /> <Reading Value="http://stackoverflow.com/questions/15908191/0.03" /> <Reading Value="http://stackoverflow.com/questions/15908191/0.53" /> </Readings> </ContiguousIntervalSet> </ContiguousIntervalSets> </Channel>\[/code\]Below is the current code I have to find the Value.\[code\] XmlReader reader = XmlReader.Create(FileLocation); while (reader.Read()) { if((reader.NodeType == XmlNodeType.Element) && (reader.Name == "Reading")) { if (reader.HasAttributes) { MessageBox.Show(reader.GetAttribute("Value")); } } }\[/code\]
 
Back
Top