You're currently trying to find an element name of MacroSample_Head1_Macro907
- whereas I believe you really want find an element named PartCount
with an attribute called name
with a value of MacroSample_Head1_Macro907
:
var element = XElement.Load("http://B-DVM-4/current");
XNamespace ns = "urn:mtconnect.org:MTConnectStreams:1.2";
var part = element.Descendants(ns + "PartCount")
.First(x => (string) x.Attribute("name") ==
"MacroSample_Head1_Macro907")
.Value;
(Or you might want to cast to decimal
instead of using Value
- presumably it is a decimal value.)
Note that the namespace is declared as the default namespace by the root element:
<MTConnectStreams ... xmlns="urn:mtconnect.org:MTConnectStreams:1.2" ...>
...
</MTConnectStreams>