I am trying to get comp1's value in the most simple way in C#. I want to be able to do it with a way that requires least checkes whether an element like Primary is there, etc.
i.e.
// pseudo code
xmlItem = root.SelectSingleNode "/Primary/Complex?Name='comp1'"
So I can just check if xmlItem
is null
, or has no elements, instead of doing many checks everytime I access a child node. Here is the xml, but the actual one is more nested, but only the leaf xml node has a specific name that we are looking for.
<?xml version="1.0" ?>
<Primary Type="">
<Simple Name="smp"></Simple>
<Complex Name="comp0" Value="123"></Complex>
<Complex Name="comp1" Value="456"></Complex>
<Complex Name="comp2" Value="789"></Complex>
</Primary>