in Education by
Greetings! I'm working on wrapping my head around LINQ. If I had some XML such as this loaded into an XDocument object: I'd like to get the attribute values of all of the Item child elements of a Group element. Here's what my query looks like: var results = from thegroup in l_theDoc.Elements("Root").Elements(groupName) select new { attrib1_val = thegroup.Element("Item").Attribute("attrib1").Value, attrib2_val = thegroup.Element("Item").Attribute("attrib2").Value, }; The query works, but if for example the groupName variable contains "GroupB", only one result (the first Item element) is returned instead of three. Am I missing something? JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
XElement e = XElement.Parse(testStr); string groupName = "GroupB"; var items = from g in e.Elements(groupName) from i in g.Elements("Item") select new { attr1 = (string)i.Attribute("attrib1"), attr2 = (string)i.Attribute("attrib2") }; foreach (var item in items) { Console.WriteLine(item.attr1 + ":" + item.attr2); }

Related questions

0 votes
    Myself and a colleague have a dispute about which of the following is more elegant. I won't say ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 10, 2022 in Education by JackTerrance
0 votes
    Is there any way to convert following SQL statement into LINQ? select ve.EntityID , fin1.FinanceStat as ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 23, 2022 in Education by JackTerrance
0 votes
    I have this XML file and am able to read it, but it breaks and returns null once it gets to the ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 27, 2022 in Education by JackTerrance
0 votes
    I'm trying to create a menu for my web site programmatically from an xml file. The menu has three ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 26, 2022 in Education by JackTerrance
0 votes
    Does independence of the judiciary mean that the judiciary is not accountable to any one? Write your answer in not more than 100 words. Please answer the above question....
asked Aug 4, 2022 in Education by JackTerrance
0 votes
    I'm considering the following: I have some data stream which I'd like to protect as secure as ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 17, 2022 in Education by JackTerrance
0 votes
    I'm considering the following: I have some data stream which I'd like to protect as secure as ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 15, 2022 in Education by JackTerrance
0 votes
    I have developed two Windows Phone applications and would like to deploy them on a physical device for a ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 4, 2022 in Education by JackTerrance
0 votes
    In C, how can i pass more than one argument to a thread? Normally, I do it in a way like, ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 11, 2022 in Education by JackTerrance
0 votes
    When there are more than one independent variables in the model, then the linear model is termed as _______ (a ... of R Programming Select the correct answer from above options...
asked Feb 10, 2022 in Education by JackTerrance
0 votes
    Is it possible that a function have more than one return statements? ,1.true,2.false Select the correct answer from above options...
asked Dec 25, 2021 in Education by JackTerrance
0 votes
    my tens digit is one more than my hundreds digit. my hundreds digit is an even number between 5 and 7. my ones ... triangle. Who am l? Select the correct answer from above options...
asked Dec 23, 2021 in Education by JackTerrance
0 votes
    which term describes a could provider allowing more than one company to share or rent the same server? Select the correct answer from above options...
asked Dec 16, 2021 in Education by JackTerrance
0 votes
    Which key do we use to edit the content of more than one sheet at a time ? Select the correct answer from above options...
asked Dec 15, 2021 in Education by JackTerrance
...