Sunny S

Sunny S

  • 1.9k
  • 9
  • 131

How to Check a Particular Element has a Value or elements ?

Oct 13 2019 6:21 AM
How to check a particular Element has a value or inner elements?
here I have a list of Students, by using the name as search key displaying their results to richtextbox but here I have a problem where it comes to smith like students, I have one more table inside it as a list of marks, how to check and display
Do that particular element have value or elements? 
I am using C# and LINQ to retrieve the data.
<Table Mode="SSC">
<Item Marks="40" Result="10.6" />
<Item Marks="100" Result="6.4" />
<Item Marks="110" Result="5.7" />
<Item Marks="120" Result="5" />
<Item Marks="130" Result="4.3" />
<Item Marks="140" Result="3.5" />
<Item Marks="150" Result="2.8" />
<Table Mode="Inter">
<Item Marks="40" Result="8.8" />
<Item Marks="50" Result="8.8" />
<Item Marks="60" Result="8.8" />
<Item Marks="70" Result="8.8" />
<Item Marks="80" Result="8.8" />
XDocument doc = XDocument.Load(@"filename");
IEnumerable<XElement> AllStudntElements = doc.Root.Elements();
var SelectDataByName = from element in AllStudntElements
where element.Element("Name").Value == SearchtItem
select element;
using for each loop it is working perfectly for every student but like smith how to check whether total marks have inner elements or not and how to display Marks and Results as a list for smith like students?
I have tried everything like **has children,hasAttribute** but nothing giving proper results?

Brought to you by: JavaScript SDK for Bold BI dashboard and analytics embedding. Free trial.

Answers (2)