Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 42947
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T15:25:04+00:00 2026-05-10T15:25:04+00:00

Greetings! I’m working on wrapping my head around LINQ. If I had some XML

  • 0

Greetings!

I’m working on wrapping my head around LINQ. If I had some XML such as this loaded into an XDocument object:

<Root>     <GroupA>         <Item attrib1='aaa' attrib2='000' attrib3='true' />     </GroupA>     <GroupB>         <Item attrib1='bbb' attrib2='111' attrib3='true' />         <Item attrib1='ccc' attrib2='222' attrib3='false' />         <Item attrib1='ddd' attrib2='333' attrib3='true' />     </GroupB>     <GroupC>         <Item attrib1='eee' attrib2='444' attrib3='true' />         <Item attrib1='fff' attrib2='555' attrib3='true' />     </GroupC> </Root> 

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T15:25:05+00:00Added an answer on May 10, 2026 at 3:25 pm
    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); } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Greetings! I have some XML like this: <Root> <MainSection> <SomeNode>Some Node Value</SomeNode> <SomeOtherNode>Some Other
Greetings, I've read some threads about this topic, but actually I was unable to
Greetings. I'm just getting started with the boost::asio library and have run into some
Greetings, My goal: To validate an XML document then load the data into a
Greetings I've been working on a homework in which I must create a linked
Greetings all. I am writing some code using the Boost Units library and have
Greetings , I am a new developer in BlackBerry Application. I have been working
Greetings! This is my first question. I've searched all over the web as well
Greetings everyone. Can any one has a working example for the CoreTelephony framework? I
Greetings I may have imagined this but does anyone know if Last.fm previously used

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.