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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:37:50+00:00 2026-05-25T06:37:50+00:00

I have following xml structure: //this is the root <factory ver=123 id=1> //can be

  • 0

I have following xml structure:

 //this is the root
<factory ver="123" id="1">
    //can be a lot of lines
   <line id="123" name="line name">
         //can be alot of machines
         <machine id="101" Type="Weel">
           <setting Title="Filled" Value="No"  />
           <setting Title="Size"   Value="14" />
           <setting Title="Mandatory" Value="No"/>
        </machine>
        <machine id="222" Type="Reel">
           <setting Title="Filled" Value="No"  />
           <setting Title="Size"   Value="14" />
           <setting Title="Mandatory" Value="No"/>
        </machine>
   </line>
  <line id="312" name="line name1">
         <machine id="111" Type="Weel">
           <setting Title="Filled" Value="No"  />
           <setting Title="Size"   Value="14" />
           <setting Title="Mandatory" Value="No"/>
        </machine>
        <machine id="333" Type="Reel">
           <setting Title="Filled" Value="No"  />
           <setting Title="Size"   Value="14" />
           <setting Title="Mandatory" Value="No"/>
        </machine>

How I can via Linq and XDocument by given machine ID to get it’s type and all it’s settings(there can be much more not listed all of them).

  • 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-25T06:37:51+00:00Added an answer on May 25, 2026 at 6:37 am

    Well, you can get to a particular machine easily like this:

    var element = doc.Descendants("machine")
                     .FirstOrDefault(x => (int) x.Attribute("id") == targetId);
    

    That will return null if there are no matching elements.

    If you want to go from that to a dictionary of setting name to setting value, you can use:

    // After checking whether `element` is null of course
    var settings = element.Elements("setting")
                          .ToDictionary(x => x.Attribute("Title").Value,
                                        x => x.Attribute("Value").Value);
    

    And the type is simple:

    var type = (string) element.Attribute("Type");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi I have the following XML structure: <Root> <Persons> <PersonList Category=Employee> <Person Name=John Id=5
I have an XML structure like the following <root> <person> <name>James</name> <description xsi:type=me:age>12</description> <description
I have an XML document with following structure: root element DataModel can have children
I have an XML file of the following structure <Root> <Child Name=First> <Data Name=a
I have this xml structure, <root> <child1> </child1> <child2> </child2> <child3 /> <extendedchild:name> </extendedchild:name>
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: <?xml version=1.0 encoding=utf-8 standalone=yes?> <Root xmlns:xsi=My Program> <NotRoot
I have an XML structure like the following: <Root> <Base> <Greeting>Base Hello!</Greeting> <SpecialMessage>Base Special
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 an XML structure like this: <?xml version=1.0 encoding=utf-8?> <categories version=2.0> <category> <name>cat1</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.