I'm struggling with accessing to the data stored in the XML file from C#. I read a lot of posts - the closest one was here - but still can't get it working.
The xml node looks like below:
<Prop Name='StartTime' Type='Number' Flags='0x0'>
<Value>171.8032865</Value>
</Prop>
I need to know what is the value of the property named 'StartTime'
EDIT: The node above is a one of the many in the xml document. And it is nested amongst other nodes. I need to find ALL values of the property with the name 'StartTime'.
I use XAML.
EDIT2: I think it'll better if I display bigger chunk of the xml I have to get the data from. It looks like Kaz's solution is the closest the demanded solution, but it fails if I load whole xml.
XML file:
<Prop Type='TEResult' Flags='0x0'>
<Prop Name='TS' Type='Obj' Flags='0x0'>
<Prop Name='SequenceCall' Type='Obj' Flags='0x0'>
<Prop Name='ResultList' Type='Array' LBound='[0]' HBound='[3]' ElementType='Obj' Flags='0x0'>
<ArrayElementPrototype Type='TEResult' Flags='0x0'>
</ArrayElementPrototype>
<Value ID='[0]'>
<Prop Type='TEResult' Flags='0x0'>
<Prop Name='Error' Type='Obj' TypeName='Error' Flags='0x400000'>
<Prop Name='Code' Type='Number' Flags='0x400000'>
<Value>0</Value>
</Prop>
<Prop Name='Msg' Type='String' Flags='0x400000'>
<Value></Value>
</Prop>
<Prop Name='Occurred' Type='Boolean' Flags='0x400000'>
<Value>False</Value>
</Prop>
</Prop>
<Prop Name='Status' Type='String' Flags='0x400000'>
<Value>Failed</Value>
</Prop>
<Prop Name='Numeric' Type='Number' Flags='0x2400'>
<Value>0</Value>
</Prop>
<Prop Name='ReportText' Type='String' Flags='0x400000'>
<Value></Value>
</Prop>
<Prop Name='Common' Type='Obj' TypeName='CommonResults' Flags='0x0'>
<Prop Name='IncludeInReport' Type='Boolean' Flags='0x0'>
<Value>True</Value>
</Prop>
</Prop>
<Prop Name='TS' Type='Obj' Flags='0x0'>
<Prop Name='StartTime' Type='Number' Flags='0x0'>
<Value>171.8032865</Value>
</Prop>
<Prop Name='TotalTime' Type='Number' Flags='0x0'>
<Value>0.0005158</Value>
</Prop>
<Prop Name='Index' Type='Number' Flags='0x0'>
<Value>0</Value>
</Prop>
<Prop Name='StepName' Type='String' Flags='0x0'>
<Value>Test 1</Value>
</Prop>
<Prop Name='StepGroup' Type='String' Flags='0x0'>
<Value>Main</Value>
</Prop>
<Prop Name='StepId' Type='String' Flags='0x0'>
<Value>ID#:TbZA+59stkivP1pqe//sUB</Value>
</Prop>
<Prop Name='Id' Type='Number' Flags='0x0'>
<Value>5</Value>
</Prop>
<Prop Name='StepType' Type='String' Flags='0x0'>
<Value>NumericLimitTest</Value>
</Prop>
<Prop Name='StepCausedSequenceFailure' Type='Boolean' Flags='0x0'>
<Value>True</Value>
</Prop>
<Prop Name='BlockLevel' Type='Number' Flags='0x0'>
<Value>0</Value>
</Prop>
</Prop>
<Prop Name='Limits' Type='Obj' Flags='0x3000'>
<Prop Name='Low' Type='Number' Flags='0x0'>
<Value>9</Value>
</Prop>
<Prop Name='High' Type='Number' Flags='0x0'>
<Value>11</Value>
</Prop>
</Prop>
<Prop Name='Comp' Type='String' Flags='0x3000'>
<Value>GELE</Value>
</Prop>
</Prop>
</Value>
<Value ID='[1]'>
<Prop Type='TEResult' Flags='0x0'>
<Prop Name='Error' Type='Obj' TypeName='Error' Flags='0x400000'>
<Prop Name='Code' Type='Number' Flags='0x400000'>
<Value>0</Value>
</Prop>
<Prop Name='Msg' Type='String' Flags='0x400000'>
<Value></Value>
</Prop>
<Prop Name='Occurred' Type='Boolean' Flags='0x400000'>
<Value>False</Value>
</Prop>
</Prop>
<Prop Name='Status' Type='String' Flags='0x400000'>
<Value>Failed</Value>
</Prop>
<Prop Name='Numeric' Type='Number' Flags='0x2400'>
<Value>0</Value>
</Prop>
<Prop Name='ReportText' Type='String' Flags='0x400000'>
<Value></Value>
</Prop>
<Prop Name='Common' Type='Obj' TypeName='CommonResults' Flags='0x0'>
<Prop Name='IncludeInReport' Type='Boolean' Flags='0x0'>
<Value>True</Value>
</Prop>
</Prop>
<Prop Name='TS' Type='Obj' Flags='0x0'>
<Prop Name='StartTime' Type='Number' Flags='0x0'>
<Value>171.8135159</Value>
</Prop>
<Prop Name='TotalTime' Type='Number' Flags='0x0'>
<Value>0.0000802</Value>
</Prop>
<Prop Name='Index' Type='Number' Flags='0x0'>
<Value>1</Value>
</Prop>
<Prop Name='StepName' Type='String' Flags='0x0'>
<Value>Test 2</Value>
</Prop>
<Prop Name='StepGroup' Type='String' Flags='0x0'>
<Value>Main</Value>
</Prop>
<Prop Name='StepId' Type='String' Flags='0x0'>
<Value>ID#:7RheSM0MDEGTAnRrrfGNcB</Value>
</Prop>
<Prop Name='Id' Type='Number' Flags='0x0'>
<Value>6</Value>
</Prop>
<Prop Name='StepType' Type='String' Flags='0x0'>
<Value>NumericLimitTest</Value>
</Prop>
<Prop Name='StepCausedSequenceFailure' Type='Boolean' Flags='0x0'>
<Value>False</Value>
</Prop>
<Prop Name='BlockLevel' Type='Number' Flags='0x0'>
<Value>0</Value>
</Prop>
</Prop>
<Prop Name='Limits' Type='Obj' Flags='0x3000'>
<Prop Name='Low' Type='Number' Flags='0x0'>
<Value>9</Value>
</Prop>
<Prop Name='High' Type='Number' Flags='0x0'>
<Value>11</Value>
</Prop>
</Prop>
<Prop Name='Comp' Type='String' Flags='0x3000'>
<Value>GELE</Value>
</Prop>
</Prop>
</Value>
<Value ID='[2]'>
<Prop Type='TEResult' Flags='0x0'>
<Prop Name='Error' Type='Obj' TypeName='Error' Flags='0x400000'>
<Prop Name='Code' Type='Number' Flags='0x400000'>
<Value>0</Value>
</Prop>
<Prop Name='Msg' Type='String' Flags='0x400000'>
<Value></Value>
</Prop>
<Prop Name='Occurred' Type='Boolean' Flags='0x400000'>
<Value>False</Value>
</Prop>
</Prop>
<Prop Name='Status' Type='String' Flags='0x400000'>
<Value>Failed</Value>
</Prop>
<Prop Name='Numeric' Type='Number' Flags='0x2400'>
<Value>0</Value>
</Prop>
<Prop Name='ReportText' Type='String' Flags='0x400000'>
<Value></Value>
</Prop>
<Prop Name='Common' Type='Obj' TypeName='CommonResults' Flags='0x0'>
<Prop Name='IncludeInReport' Type='Boolean' Flags='0x0'>
<Value>True</Value>
</Prop>
</Prop>
<Prop Name='TS' Type='Obj' Flags='0x0'>
<Prop Name='StartTime' Type='Number' Flags='0x0'>
<Value>171.8240739</Value>
</Prop>
<Prop Name='TotalTime' Type='Number' Flags='0x0'>
<Value>0.000081</Value>
</Prop>
<Prop Name='Index' Type='Number' Flags='0x0'>
<Value>2</Value>
</Prop>
<Prop Name='StepName' Type='String' Flags='0x0'>
<Value>Test 3</Value>
</Prop>
<Prop Name='StepGroup' Type='String' Flags='0x0'>
<Value>Main</Value>
</Prop>
<Prop Name='StepId' Type='String' Flags='0x0'>
<Value>ID#:pWFWDejvo0GThcOYVssHBA</Value>
</Prop>
<Prop Name='Id' Type='Number' Flags='0x0'>
<Value>7</Value>
</Prop>
<Prop Name='StepType' Type='String' Flags='0x0'>
<Value>NumericLimitTest</Value>
</Prop>
<Prop Name='StepCausedSequenceFailure' Type='Boolean' Flags='0x0'>
<Value>False</Value>
</Prop>
<Prop Name='BlockLevel' Type='Number' Flags='0x0'>
<Value>0</Value>
</Prop>
</Prop>
<Prop Name='Limits' Type='Obj' Flags='0x3000'>
<Prop Name='Low' Type='Number' Flags='0x0'>
<Value>9</Value>
</Prop>
<Prop Name='High' Type='Number' Flags='0x0'>
<Value>11</Value>
</Prop>
</Prop>
<Prop Name='Comp' Type='String' Flags='0x3000'>
<Value>GELE</Value>
</Prop>
</Prop>
</Value>
<Value ID='[3]'>
<Prop Type='TEResult' Flags='0x0'>
<Prop Name='Error' Type='Obj' TypeName='Error' Flags='0x400000'>
<Prop Name='Code' Type='Number' Flags='0x400000'>
<Value>0</Value>
</Prop>
<Prop Name='Msg' Type='String' Flags='0x400000'>
<Value></Value>
</Prop>
<Prop Name='Occurred' Type='Boolean' Flags='0x400000'>
<Value>False</Value>
</Prop>
</Prop>
<Prop Name='Status' Type='String' Flags='0x400000'>
<Value>Failed</Value>
</Prop>
<Prop Name='Numeric' Type='Number' Flags='0x2400'>
<Value>0</Value>
</Prop>
<Prop Name='ReportText' Type='String' Flags='0x400000'>
<Value></Value>
</Prop>
<Prop Name='Common' Type='Obj' TypeName='CommonResults' Flags='0x0'>
<Prop Name='IncludeInReport' Type='Boolean' Flags='0x0'>
<Value>True</Value>
</Prop>
</Prop>
<Prop Name='TS' Type='Obj' Flags='0x0'>
<Prop Name='StartTime' Type='Number' Flags='0x0'>
<Value>171.8270851</Value>
</Prop>
<Prop Name='TotalTime' Type='Number' Flags='0x0'>
<Value>0.0001041</Value>
</Prop>
<Prop Name='Index' Type='Number' Flags='0x0'>
<Value>3</Value>
</Prop>
<Prop Name='StepName' Type='String' Flags='0x0'>
<Value>Test 4</Value>
</Prop>
<Prop Name='StepGroup' Type='String' Flags='0x0'>
<Value>Main</Value>
</Prop>
<Prop Name='StepId' Type='String' Flags='0x0'>
<Value>ID#:w+ziJ/u2bkWz+F3kWa4mpC</Value>
</Prop>
<Prop Name='Id' Type='Number' Flags='0x0'>
<Value>8</Value>
</Prop>
<Prop Name='StepType' Type='String' Flags='0x0'>
<Value>NumericLimitTest</Value>
</Prop>
<Prop Name='StepCausedSequenceFailure' Type='Boolean' Flags='0x0'>
<Value>False</Value>
</Prop>
<Prop Name='BlockLevel' Type='Number' Flags='0x0'>
<Value>0</Value>
</Prop>
</Prop>
<Prop Name='Limits' Type='Obj' Flags='0x3000'>
<Prop Name='Low' Type='Number' Flags='0x0'>
<Value>9</Value>
</Prop>
<Prop Name='High' Type='Number' Flags='0x0'>
<Value>11</Value>
</Prop>
</Prop>
<Prop Name='Comp' Type='String' Flags='0x3000'>
<Value>GELE</Value>
</Prop>
</Prop>
</Value>
</Prop>
<Prop Name='SequenceFile' Type='String' Flags='0x0'>
<Value>C:\Users\Public\Documents\National Instruments\TestStand 2010 SP1\Sequence File 16.seq</Value>
</Prop>
<Prop Name='Sequence' Type='String' Flags='0x0'>
<Value>MainSequence</Value>
</Prop>
<Prop Name='Status' Type='String' Flags='0x0'>
<Value>Failed</Value>
</Prop>
</Prop>
<Prop Name='StartTime' Type='Number' Flags='0x0'>
<Value>171.6948629</Value>
</Prop>
<Prop Name='TotalTime' Type='Number' Flags='0x0'>
<Value>0.1359434</Value>
</Prop>
<Prop Name='ModuleTime' Type='Number' Flags='0x0'>
<Value>0.1357157</Value>
</Prop>
<Prop Name='Index' Type='Number' Flags='0x0'>
<Value>31</Value>
</Prop>
<Prop Name='StepName' Type='String' Flags='0x0'>
<Value>MainSequence Callback</Value>
</Prop>
<Prop Name='StepGroup' Type='String' Flags='0x0'>
<Value>Main</Value>
</Prop>
<Prop Name='StepId' Type='String' Flags='0x0'>
<Value>ID#:xnW0PT0ORE2el7wF7uaxyB</Value>
</Prop>
<Prop Name='Id' Type='Number' Flags='0x0'>
<Value>4</Value>
</Prop>
<Prop Name='StepType' Type='String' Flags='0x0'>
<Value>SequenceCall</Value>
</Prop>
<Prop Name='BlockLevel' Type='Number' Flags='0x0'>
<Value>0</Value>
</Prop>
<Prop Name='SequenceFilePostResultListEntry' Type='Obj' Flags='0x0'>
<Prop Name='ResultList' Type='Array' LBound='[0]' HBound='[]' ElementType='Obj' Flags='0x0'>
<ArrayElementPrototype Type='TEResult' Flags='0x0'>
</ArrayElementPrototype>
</Prop>
<Prop Name='SequenceFile' Type='String' Flags='0x0'>
<Value>C:\Program Files\National Instruments\TestStand 2010 SP1\Components\Models\TestStandModels\SequentialModel.seq</Value>
</Prop>
<Prop Name='Sequence' Type='String' Flags='0x0'>
<Value>SequenceFilePostResultListEntry</Value>
</Prop>
<Prop Name='Status' Type='String' Flags='0x0'>
<Value>Passed</Value>
</Prop>
</Prop>
</Prop>
Ok....after getting the whole xml...
XDocument xmlDoc = XDocument.Load(@"Your file path");
var startTimes = xmlDoc.Descendants()
.Where(x => x.Attributes().Any(att => att.Name == "Name" && att.Value == "StartTime"))
.Select(x => x.Value).ToList();
This gives me a list containing the values:
This feels more like what you're looking for.