Jump to content


Photo
- - - - -

Using To Return A Specific Child Element In C#


  • Please log in to reply
No replies to this topic

#1 Mike7889

Mike7889

    New Member

  • Members
  • Pip
  • 1 posts

Posted 09 July 2014 - 09:12 AM

Given the attached XML file, I need to get the value for a specific child element. I can currently get a list of all of the elements, but haven't been able to extract a specific child.

I am using XElement to load the document and would like to continue with this method. Specifically, I need to get the value of the child "SpindleSpeed." and assign it to the variable sSpeed. I was able to bring in the entire list of Children, but not just one.

Please help!

XElement root = XElement.Load(3axis_current.xml);
XNamespace mt = root.Name.Namespace;
IEnumerable<XElement> devices =
from dev in root.Descendants (mt + "DeviceStream")
select dev;
{
IEnumerable<XElement> samples =
from res in cs.Descendants(mt + "Samples")

select res;

foreach (XElement ev in samples)
{
IEnumerable<XElement> children = ev.Elements();
foreach (XElement re in children)
results.Add(new Sample(re, dev));
}
}
return results;




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users