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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:14:45+00:00 2026-05-23T15:14:45+00:00

<Fruit> <Apple> <Pear>dar</Pear> <Orange/> <Starfruit>har</Starfruit> </Apple> <Lemon> <Melon>yar</Melon> <Lime>blah</Lime> </Lemon> <Fruit> At the moment

  • 0
<Fruit>
    <Apple>
        <Pear>dar</Pear>
        <Orange/>
        <Starfruit>har</Starfruit>
    </Apple>
    <Lemon>
        <Melon>yar</Melon>
        <Lime>blah</Lime>
    </Lemon>
<Fruit>

At the moment I have two select statements and then storing the values from those two separate enumerations into an object.

        var myfruits = from myfruit in document.Descendants("UserAccount")
                   select new
                   {
                       Pear= myfruit.Element("Pear").Value,
                       Starfruit= myfruit.Element("Starfruit").Value,

                   };
        var myfruits2 = from myfruit2 in document.Descendants("Product")
                    select new
                    {
                        Melon= myfruit2.Element("Melon").Value,
                        Lime= myfruit2.Element("Lime").Value,
                    };
        foreach (var myfruit in myfruits)
        {
            megafruit.Pear=myfruit.Pear;
            megafruit.Starfruit=myfruit.Starfruit;
        }
        foreach (var myfruit2 in myfruits2)
        {
            megafruit.Melon= myfruit2.Melon;
            megafruit.Lime= myfruit2.Lime;
        }
        return megafruit;
  • 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-23T15:14:46+00:00Added an answer on May 23, 2026 at 3:14 pm

    You can navigate the XML document when you expand the query results (since you have a collection of all the descendant nodes). Something like this:

    XDocument document = XDocument.Parse("<Fruit><Apple><Pear>dar</Pear><Orange/><Starfruit>har</Starfruit></Apple><Lemon><Melon>yar</Melon><Lime>blah</Lime></Lemon></Fruit>");
    
    var megafruit = (from x in document.Descendants("Fruit")
                     select new
                     {
                         Pear = x.Element("Apple").Element("Pear").Value,
                         Orange = x.Element("Apple").Element("Orange").Value,
                         Starfruit = x.Element("Apple").Element("Starfruit").Value,
                         Melon = x.Element("Lemon").Element("Melon").Value,
                         Lime = x.Element("Lemon").Element("Lime").Value
                     }).SingleOrDefault();
    

    This will generate an anonymous class that has the properties filled with the values of the supplied XML. Alternatively, you can also use select new Megafruit() rather than just select new – which would create a new instance of the Megafruit class with the properties set according to the XML.

    Note that this is a very simple example, assuming one occurrence of each of the fruits – it’s similiar to something I did at work many moons ago, where I knew the data I was getting was not going to be a collection (like a collection fo pears, or oranges, or whatever) so I coudl use SingleOrDefault.

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

Sidebar

Related Questions

Say I have three tables: Fruit (Table 1) ------ Apple Orange Pear Banana Produce
I have a list: >data<- list(Apple=12,orange=4,pear=5) >fruit<- Apple Now I extract the value for
I have two arrays: array1( 'Apple', 'Pear', 'Banana', 'Apricot', 'Watermelon', 'Peach', 'Pineapple', 'Strawberry', 'Melon',
For example, i have checkboxes: <input type='checkbox' name='fruit' value='apple'> Apple <input type='checkbox' name='fruit' value='orange'>
I have a simple simulated array with two elements: bowl["fruit"] = "apple"; bowl["nuts"] =
Let's say you have an array of strings such as: var fruit = [apple,peach,pear,plum];
ID FRUIT 1 Apple 2 Orange 3 Apple 4 Pear 5 Apple 6 Pear
Suppose I have this: <div id=apple class=fruit></div> <div id=orange class=fruit></div> <div id=grape class=fruit></div> <div
I have: class fruit { } class apple:fruit { } class pear:fruit { }
I have the following PHP array: array(Apple, Pear, Grape, Orange) And I'd like to

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.