Note that there are some explanatory texts on larger screens.

plurals
  1. POConditional Linq to XML select (nested select statements)
    primarykey
    data
    text
    <p>I'm trying to view all my friends from facebook who went to some school. I use FQL to get an xml file that contains all my friends with their education info. But i can't use FQL to select only those who went to the same school. Therefor, I'm trying to use Linq to XML to select only the users i want. I've tried some methods but those won't work for me.</p> <p>Here is my linq query:</p> <pre><code>XDocument doc = RemoveNamespace (XDocument.Load(url)); string[] search = {"Katho", "katho", "kortrijk" , "vhti"}; List&lt;string&gt; keys = new List&lt;string&gt;( search ); var user = (from usr in doc.Descendants("user") select new fbUser { name = usr.Element("name").Value, email = usr.Element("email").Value, current_location = StringExtensions.checkNull(usr.Element("current_location").Value,""), hometown_location = usr.Element("hometown_location").Value, pic = StringExtensions.checkNull(usr.Element("pic_square").Value,"http://www.fox16.com/media/avatar/default.jpg"), education_history = (from edu in usr.Descendants("education_info") //where usr.Element("education_history").HasElements where keys.Contains(edu.Element("name").Value) select new Education { name = StringExtensions.checkNull(edu.Element("name"),""), year = StringExtensions.checkNull(edu.Element("year"),""), school_type = StringExtensions.checkNull(edu.Element("school_type"),""), concentrations = from conc in edu.Descendants("concentrations") where (edu.Element("concentrations").HasElements) select new Concentration { name = StringExtensions.checkNull(conc.Element("concentration").Value, "") } }) }).Take(5) ; </code></pre> <p>EDIT: sample xml can be found here:<a href="http://pastebin.com/ayVUZL2x" rel="nofollow">sample XML</a></p> <p>There's one more problem. The school name is not an direct attribute from the fbUser object. Also in the xml file the schoolname can only be found here</p> <pre><code>&lt;user&gt;&lt;education_history&gt;&lt;education_info&gt;&lt;name&gt; </code></pre> <p>So here is my where statement:</p> <pre><code>where usr.Element("education_history").Element("education_info").Element(name").value == "schoolname" </code></pre> <p>Problem is that there is not always an education_history or education_info node in the xml. </p> <p>So i also need a way to work around this..</p> <p>Any help on this problem is very appreciated.</p> <p>I hope you can help me!</p> <p>Grtz</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload