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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T17:37:07+00:00 2026-05-29T17:37:07+00:00

I’m some what new to linq could uses some help.. I have an xml

  • 0

I’m some what new to linq could uses some help..

I have an xml file that looks like this:

  <InputPath>
      <path isRename="Off" isRouter="Off" pattern="pattern-1">d:\temp1</path>
      <path isRename="Off" isRouter="pattern-1">d:\temp2</path>
  </InputPath>

I need to loop through and get the key values of the tag “path”.

What I have so far is

var results = from c in rootElement.Descendants("InputPath") select c;

foreach (XElement _path in results)
{
    string value = _path.Element("path").Value;
}

But I only get the last <path> value. Any help would be great.

  • 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-29T17:37:21+00:00Added an answer on May 29, 2026 at 5:37 pm

    You’ll only get the first element that way, because that’s what the Element method gives you: the first child element with the given name.

    If you want multiple elements you can just use Elements instead:

    // Note: the query expression here is pointless.
    var results = from c in rootElement.Descendants("InputPath") select c;
    foreach (XElement _path in results)
    {
        string value = _path.Elements("path").Value;
        // Use value here...        
    }
    

    Alternatively, use the Elements extension method and do it all in one go:

    foreach (var path in rootElement.Descendants("InputPath").Elements("path"))
    {
        string value = path.Value;
        // Use value here  
    }
    

    If that doesn’t help, please give more information about what you’re trying to do and what the problem is.

    If by “last” you mean “the element contents” that’s because you’re using the Value property. If you want the attributes within the path element, you need the Attribute method, as shown by IamStalker, although personally I’d usually cast the XAttribute to string (or whatever) rather than using the Value property, in case the attribute is missing. (It depends on what you want the behaviour to be in that case.)

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have some data like this: 1 2 3 4 5 9 2 6
For some reason, after submitting a string like this Jack’s Spindle from a text
I have just tried to save a simple *.rtf file with some websites and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I've got a string that has curly quotes in it. I'd like to replace
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported

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.