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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T01:16:54+00:00 2026-06-04T01:16:54+00:00

I am just trying to read some details from an XML file, part of

  • 0

I am just trying to read some details from an XML file, part of which looks like this:

<appender name="FILE" class="applications.core.logging.CustomFileAppender">
    <param name="File" value="C:\\Logs\\File.log"/>
    <param name="MaxBackupIndex" value="5"/>
</appender>
<appender name="FILE" class="applications.core.logging.CustomFileAppender">
    <param name="File" value="C:\\Logs\\File2.log"/>
    <param name="MaxBackupIndex" value="17"/>
</appender>
<appender name="FILE" class="applications.core.logging.CustomFileAppender">
    <param name="File" value="C:\\Logs\\File3.log"/>
    <param name="MaxBackupIndex" value="98"/>
</appender>

I have several of these ‘appender’ nodes in my XML file. The following code loops through each ‘appender’ node. Within each ‘appender’ I want to pick out the param node with name “File” and check if the value is equal to what I am looking for.

foreach (XElement node in XmlFile.Descendants("appender"))
        {
            IEnumerable<XElement> elements = from el in node.Elements("param") 
                                             where el.Attribute("value").ToString().Equals("C:\\Logs\\File.log")) 
                                             select el;

            foreach (XElement el in elements)
            {
                Console.WriteLine("Found it " + el.Name);
                // Now read value for MaxBackupIndex
            }
        }

However my code is not printing anything out, so I think possibly the ‘where’ part of my LINQ query is incorrect, can anybody spot where I am going wrong?

  • 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-04T01:16:55+00:00Added an answer on June 4, 2026 at 1:16 am

    You’re calling XAttribute.ToString(). Try using XAttribute.Value instead, or just cast to a string. ToString() will return value="C:\\Logs\\File.log" – the name and the value – whereas you just want the value:

    var elements = from el in node.Elements("param")
                   where (string) el.Attribute("value") == "C:\\Logs\\File.log"
                   select el;
    

    Personally I wouldn’t bother with a query expression here, btw:

    var elements = node.Elements("param")
             .Where(el => (string) el.Attribute("value") == "C:\\Logs\\File.log")
    

    EDIT: Additionally, as others have said, you want to have single backslashes in the XML file.

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

Sidebar

Related Questions

Hi I am trying to read an xml file from outside the web-app container,
I am trying to read in some values from a file in an octave
For just some fun i am trying to use Flat File databases to read
I am trying to read some XML received from an external interface over a
I'm just trying to do a simple text file read in java for my
I just read about HTML 5's WebSocket interface. How can I start trying this?
I am trying to read some Java code from a tutorial, I don't understand
I've just installed an Oracle express database and am trying to read some data
I have a simplistic app (just learning) that reads some XML data from a
I have a ini file which contains some sample values like: [Section1] Value1 =

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.