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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T13:11:52+00:00 2026-05-11T13:11:52+00:00

My requirement here is to retrieve the node that matches the hostname (for eg.

  • 0

My requirement here is to retrieve the node that matches the hostname (for eg. machine1) and I always get back no results. Please let me know what the problem is?

Thanks for the help in advance!!!

XDocument configXML = XDocument.Load('the below xml');  var q = from s in configXML.Descendants('lcsetting')     where ((string)s.Element('host') == hostName)                             select s; 

The actual xml:

<lcsettings>   <lcsetting env='prod'>     <hosts usagelogpath=''>       <host>machine1</host>       <host>machine2</host>       <host>machine3</host>     </hosts>   </lcsetting>   <lcsetting env='qa'>     <hosts usagelogpath=''>       <host>machine4</host>       <host>machine5</host>       <host>machine6</host>     </hosts>   </lcsetting>   <lcsetting env='test'>     <hosts usagelogpath=''>       <host>machine7</host>       <host>machine8</host>       <host>machine9</host>     </hosts>   </lcsetting> </lcsettings> 
  • 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. 2026-05-11T13:11:52+00:00Added an answer on May 11, 2026 at 1:11 pm

    You’re looking for a host element directly under an lcsetting – that doesn’t occur because there’s always a hosts element between the two in the hierarchy. You’re also using Element instead of Elements, which means only the first element with the right name will be returned.

    You could use Descendants again instead of Element… but you’ll need to change the condition. Something like:

    var q = from s in configXML.Descendants('lcsetting')         where s.Descendants('host').Any(host => host.Value == hostName)         select s; 

    Alternatively, you could make your query find host elements and then take the grandparent element in each case:

    var q = from host in configXML.Descendants('host')         where host.Value == hostName         select host.Parent.Parent; 

    (This assumes a host element will only occur once per lcsetting; if that’s not the case, you can add a call to Distinct.)

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

Sidebar

Related Questions

Here is my requirement; I have a form where I get some account number
I am creating a installer using WIX, The requirement here is that when the
Here's my requirement: 1. I want my installable to have a custom license agreement
Here is simplified version of my requirement I have a java class say Processor
First question here so hello everyone. The requirement I'm working on is a small
I want to model messages between users, here is the requirement: User has received
Here are the requirements: Must be alphanumeric, 8-10 characters so that it is user
Requirement : Should update MySQL database with that of MS Sql Server updates which
I am maintaining a Python script that uses xlrd to retrieve values from Excel
I'm deploying an MVC3 app that stores images in a database. The requirement is

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.