I have an xml file say (test.xml)
<root loc-ver="1.0">
<data name="String1" xml:space="preserve">
<value loc="root_data_value_2">Description number1</value>
</data>
<data name="String2" xml:space="preserve">
<value loc="root_data_value_3">Description number 2</value>
</data>
</root>
Now, if
I specify the name = “String1”, I should get the value as “Description number1”
I specify the name = “String2”, I should get the value as Description number2
I am trying with the approach, by no result
XDocument doc = XDocument.Load(@"D:\test.xml");
string search = "String10";
var lv1s = from lv1 in doc.Descendants("data")
select lv1.Name;
Sounds like you want:
You should consider what you want to happen if there isn’t exactly one result. Is that an error state (if so, use
Single()), should you use all the results (if so, just iterate overquery), should you use the first result if it’s available, and ignore it otherwise (if so, useFirstOrDefault()and check if the result is null), should you use the first result, and it’s an error if there aren’t any (if so, useFirst()).