O'Reilly Forums: Using To Return A Specific Child Element In C# - O'Reilly Forums

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Using To Return A Specific Child Element In C# Rate Topic: -----

#1 User is offline   Mike7889 

  • New Member
  • Pip
  • Group: Members
  • Posts: 1
  • Joined: 09-July 14

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

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users