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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T23:58:03+00:00 2026-06-17T23:58:03+00:00

I have the following xml structure <userlist> <user Name=something> <function name=funcname> <picture name=pictname> <curve

  • 0

I have the following xml structure

<userlist>
  <user Name="something">
    <function name="funcname">
      <picture name="pictname">
         <curve name="curvename">
          <name>NAME</name>
          ...
         </curve>
      </picture>
     </function>
     <function name="function2">
     ...
     </function>
   </user>

It goes on a bit more. I have written a function to extract of the “function” tags and place them in objects using code that simplifies to this:

from function in xmlDoc.Descendants("function")
select new FUNCTIONOBJECT {
 do all the rest...
 }.toList<FUNCTIONOBJECT>();

I am now trying to make it so that I only filter the functions for a given user. so the name attribute of the user is given. Can anyone tell me how I can make this work with LINQ?
My attempt was:

from user in xmlDoc.Descendants("user")
where user.Attribute("Name").Value == givenusername
select {
   var functions =
     from function in user.Descendants("function")
     select new FUNCTIONOBJECT {
     ... more stuff
     }.toList<FUNCTIONOBJECT>();

But this is wrong and doesnt work.
All help is good. I am pretty new to c# and still trying to wrap my head around xml parsing with LINQ.

EDIT:
updated version of what I have and still doesnt work:

XDocument xmlDoc = XDocument.Load(path);

        var functionlist =
            (from user in xmlDoc.Descendants("user")
             where user.Attribute("Name").Value == username
             select(
             (from function in user.Descendants("function")
             select new Function
             {
                 name = function.Attribute("name").Value,
                 pictures =
                    (from picture in function.Descendants("picture")
                     select new Picture
                     {
                         name = picture.Attribute("name").Value,
                         layout = picture.Element("layout").Value,
                         curves =
                            (from curve in picture.Descendants("curve")
                             select new Curve
                             {
                                 name = curve.Attribute("name").Value,
                                 section = curve.Element("section").Value,
                                 run = curve.Element("run").Value,
                                 folder = curve.Element("folder").Value,
                                 drivingpoint = curve.Element("drivingpoint").Value,
                                 display = int.Parse(curve.Element("display").Value),
                                 points =
                                    (from point in curve.Descendants("point")
                                     select new Point
                                     {
                                         id = point.Element("id").Value != null ? point.Element("id").Value : string.Empty,
                                         direction = point.Element("direction").Value != null ? point.Element("direction").Value : string.Empty,
                                     }).ToList<Point>(),
                             }).ToList<Curve>(),
                     }).ToList<Picture>(),
             }).ToList<Function>(),
             ).toList();
    }
  • 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-06-17T23:58:05+00:00Added an answer on June 17, 2026 at 11:58 pm

    Just few syntax mistakes. Otherwise, the content was correct. Its a bit tricky to learn C# and LINQ syntax at the same time (a language in a language). Here is the corrected code:

    from user in xmlDoc.Descendants("user")
    where user.Attribute("Name").Value == givenusername
    select ((from function in user.Descendants("function")  // When you do a "select something" "something" must have a value, so you can't begin with "{ var functions = ..."
             select new FUNCTIONOBJECT 
             {
                 // more stuff
             }).ToList();  // You don't have to specify <FUNCTIONOBJECT> because the compiler deduce it from the context (here there a new FUNCTIONOBJECT
    

    But here, you will have a List<List<FUNCTIONOBJECT>>. Why? Because there is no information in the code that specify that only 1 user has the givenusername.

    If it is the case, just split the code:

    // Gets the user
    var user = (from user in xmlDoc.Descendants("user")
                where user.Attribute("Name").Value == givenusername
                select user).Single();  // Get the only user that satisfy the condition (Throw an exception if no user has the given name or if multiple users have the given name)
    
    // Gets its functions
    List<FUNCTIONOBJECT> functions = (from function in user.Descendants("function")
                                      select new FUNCTIONOBJECT 
                                      {
                                          // more stuff
                                      }).ToList();  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following XML structure: <agencies> <city> <name>New York</name> <address>Street A, 101</address> <phone>111-222-333</phone>
I have the following XML structure <root> <OuterLevel> <Node> <Name>NodeA</Name> </Node> <Node> <Name>NodeB</Name> <Node>
I have the following XML structure: <node name=A> <node name=B> <node name=C/> <node name=D/>
I have the following XML structure: <row> <field name=Id>1</field> <field name=AreaId>1</field> <field name=Name>ת&quot;א</field> </row>
I have the following XML structure: <method constructor=true name=Main public=true> <parameterList/> <block> <call> <callAttrbute>
Hi I have the following XML structure: <Root> <Persons> <PersonList Category=Employee> <Person Name=John Id=5
one more problem. I have following structure of XML: <player> <id>12</id> <name>pl_name</name> <experience> <points>147</points>
I have the following XML structure: <Capabilities> <Capability ID=1 Name=Capability # 1> <Relations> <Relation
So i have the following xml structure: <Application> <Properties> <Property> <Name>blabla</Name> <Value>123</Value> </Property> </Properties>
I have the following XML structure. <?xml version=1.0 encoding=UTF-8?> <root> <header> <row> <column n=name

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.