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

  • SEARCH
  • Home
  • 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 881035
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T12:11:47+00:00 2026-05-15T12:11:47+00:00

I’ve an xml file (Sample.xml) which has the following structure <RootElement> <Children> <Child Name=FirstChild

  • 0

I’ve an xml file (Sample.xml) which has the following structure

<RootElement> 
 <Children> 
    <Child Name="FirstChild" Start="0" End="2"> 
      <Sibling Name="Test1" /> 
      <Sibling Name="Test2" /> 
      <AdditionalSibling Name="Add_Test_1" /> 
      <AdditionalSibling Name="Add_Test_2" /> 
      <MissingSibling Name="Miss_Test_1" /> 
      <MissingSibling Name="Miss_Test_2" / 
 </Child> 

 <Child Name="SecondChild" Start="0" End="2"> 
      <Sibling Name="Test3" /> 
      <Sibling Name="Test4" /> 
 </Child> 
 <Child Name="ThirdChild" Start="0" End="2"> 
      <Sibling Name="Test5" /> 
      <Sibling Name="Test6" /> 
  </Child> 
  <Child Name="FourthChild" Start="0" End="2"> 
      <Sibling Name="Test7" /> 
      <Sibling Name="Test8" /> 
  </Child> 
  <Child Name="FifthChild" Start="0" End="2"> 
      <Sibling Name="Test9" /> 
      <Sibling Name="Test10" /> 
  </Child> 
  <Child Name="SixthChild" Start="0" End="2"> 
      <Sibling Name="Test11" /> 
      <Sibling Name="Test12" /> 
  </Child> 

  <MatchedChilds> 
     <Child Name="FirstChild" /> 
     <Child Name="SecondChild" /> 
     <Child Name="ThirdChild" /> 
     <Child Name="FourthChild" /> 
     <Child Name="FifthChild" /> 
     <Child Name="SixthChild" />  
  </MatchedChilds> 
 </Children> 
</RootElement> 

i need to read the attribute values of the element” Child” which is directly under “RootElement”

Now i’m using the LINQ query like

          List<string> lst = (from element in XDocument.Load(Application.StartupPath + "\\Sample.xml")
                                                       .Descendants("Child")
                                                        group element by element.Attribute("Name").Value into KeyGroup select KeyGroup.Key )
                                                       .ToList();

but it returns the attribute value of “Name” of all the “Child” element in the file.

Please give me a better solution to do this using XML to LINQ

Thanks in advance

  • 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. Editorial Team
    Editorial Team
    2026-05-15T12:11:48+00:00Added an answer on May 15, 2026 at 12:11 pm

    Use something like this:

    XDocument doc = XDocument.Load(Application.StartupPath + "\\Sample.xml");
    List<string> lst = doc.Root.Elements("Child")
                          .Select(x => (string) x.Attribute("Name"))
                          .ToList();
    

    Note the use of Elements() instead of Descendants(). That will get you all the name attributes. It’s unclear to me why you were grouping in your original sample code, but hopefully this will get you going.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
i want to parse a xhtml file and display in UITableView. what is the
I am currently running into a problem where an element is coming back from
this is what i have right now Drawing an RSS feed into the php,

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.