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 1058443
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T18:01:44+00:00 2026-05-16T18:01:44+00:00

I have been trying to parse this xml in c# <schema uri=http://blah.com/schema > <itemGroups>

  • 0

I have been trying to parse this xml in c#

<schema uri=http://blah.com/schema >
   <itemGroups>
     <itemGroup description="itemGroup1 label="itemGroup1">
       <items>
        <item description="The best" itemId="1" label="Nutella"/>
        <item description="The worst" itemId="2" label="Vegemite"/>
       </items>
     </itemGroup>
   </itemGroups>
</schema>

\itemGroup1\Nutella-The best
\itemGroup1\Vegemite-The worst

Any help or direction would be appreciated.

  • 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-16T18:01:44+00:00Added an answer on May 16, 2026 at 6:01 pm
    XDocument xDoc = XDocument.Load(myXml); //load your XML from file or stream
    
    var rows = xDoc.Descendants("item").Select(x => string.Format(
                        @"\{0}-{1}\{2}-{3}",
                        x.Ancestors("itemGroup").First().Attribute("description").Value,
                        x.Ancestors("itemGroup").First().Attribute("label").Value,
                        x.Attribute("label").Value,
                        x.Attribute("description").Value));
    

    Let’s break down what we’re doing:

    • xDoc.Descendants("item") gets us all <item> elements in the entire document

    • Select(x => string.Format(format, args) projects each <item> we got from the last operation into whatever format we specify in the lambda. In this case, a formatted string.

    • In terms of the XML tree, we’re “sitting at” the <item> level, so we need to roll back up the tree to get the data for the parent group using Ancestors. Since that method returns a sequence of elements, we know we want the first (nearest to us) so we can read its attribute.

    Now you have an IEnumerable<string>, one for each <item> in your XML document and the information in the format you specified:

    foreach(string row in rows)
    {
        Console.WriteLine(row);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been trying to parse this ( http://app.calvaryccm.com/mobile/android/v1/devos ) URL using a SAX
ok this is driving me crazy. I have been trying to parse a xml
I have been trying to parse the bottom table on this site using different
I have been using this code to parse xml till now. Its was working
I have been trying to parse for this certain piece of text in a
I have been trying to parse a file with xml.etree.ElementTree : import xml.etree.ElementTree as
I've been trying to use buildExpressionParser to parse a language, and I almost have
Have been trying to encrypt an xml file to a string so that I
Have have been trying to make a validator for my xml files. I have
I am new to XML and have been trying some simple examples and they

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.