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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T02:18:32+00:00 2026-06-15T02:18:32+00:00

<root> <level1> <item id=1 date= name= > <item id=2 date= name= > <item id=3

  • 0
 <root>
    <level1>
        <item id="1" date="" name="" >
        <item id="2" date="" name="" >
        <item id="3" date="" name="" >
        <item id="4" date="" name="" >
        <item id="5" date="" name="" >
    </level1>
 </root>

I have an xml structure like the one above.

I used

XmlNodeList xnList = xmlDoc.SelectNodes("/level1");

If I used xmlnodelist as above, how can I specifically only get the element with id=”3″?

or more useful if I could store all elements inside as elements in xnlist?

  • 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-15T02:18:33+00:00Added an answer on June 15, 2026 at 2:18 am
    XmlNodeList xnList = xmlDoc.SelectNodes("//level1/item[@id='3']");
    

    and if you want to use Linq To Xml

    var xDoc = XDocument.Parse(xmlstring); // XDocument.Load(filename)
    var items = xDoc.Descendants("level1")
                    .First()
                    .Elements("item")
                    .Select(item => new { 
                                        ID = item.Attribute("id").Value, 
                                        Name = item.Attribute("name").Value 
                                    })
                    .ToList();
    

    You can even combine XPath and Linq2Xml

    var item2 = xDoc.XPathSelectElements("//level1/item")
                    .Select(item => new { 
                                        ID = item.Attribute("id").Value, 
                                        Name = item.Attribute("name").Value 
                                    })
                    .ToList();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this XML: <root> <tab name=Detail> <section name=mysection> <items level=1> <Idx_name>9</Idx_name> <Type>mytype</Type> <item
say I have xml in a SQL xml type field e.g. @x='<root> <item> <title></title>
I have currently the following problem. I have a directory structure like root -
Given xml that looks like this: <Root> <Fruittree name=Apple ID=2> <Branch name=West ID=1> <Fruit
Suppose I get the following XML structure: <root> <item> <item1>text1</item1> <item2>text2</item2> more text here
Suppose I have a tar that contains: / # Root directory /level1/ # A
I have a RSS feed in an XML file at the root level. I
I have two processes - a user process and a root-level LaunchDaemon. I'd like
I have a Treeview control with each item having a checkbox. At root level
I have this problem for xslt: This is the input file: <root> <header/> <item/>

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.