Thursday, 19 September 2013

How to find value of an attribute in a sub child node of an XML?

How to find value of an attribute in a sub child node of an XML?

I have a XML which has the following structure:
<Results>
<TestResultAggregation testName="MyOrder">
<Counters error="0" failed="1" timeout="0" aborted="0" inconclusive="0"/>
<InnerResults>
<UnitTestResult testName="TestMethod3" outcome="Failed">
<Output>
<ErrorInfo>
<Message>Assert.Fail failed. </Message>
<StackTrace>
at Random.UnitTest1.TestMethod3()
</StackTrace>
</ErrorInfo>
</Output>
</UnitTestResult>
<UnitTestResult testName="TestMethod2" outcome="Passed">
<Output>
</Output>
</UnitTestResult>
</InnerResults>
</TestResultAggregation>
When the result of 'outcome' attribute in 'UnitTestResult' is 'failed', I
have to display the value of 'ErrorInfo' and 'StackTrace' nodes too. The
catch here is that the above schema is not fixed. For eg,
<Results>
<UnitTestResult testName="TestMethod3" outcome="Failed">
<Output>
<ErrorInfo>
<Message>Assert.Fail failed. </Message>
<StackTrace>
at Random.UnitTest1.TestMethod3()
</StackTrace>
</ErrorInfo>
</Output>
</UnitTestResult>
<UnitTestResult testName="TestMethod2" outcome="Passed">
<Output>
</Output>
</UnitTestResult>
The above schema can also be generated dynamically.
How to write a code for the above requirement in C#??

No comments:

Post a Comment