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

  • Home
  • SEARCH
  • 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 40799
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T15:04:49+00:00 2026-05-10T15:04:49+00:00

Greetings. I’m looking for a way to parse a number of XML files in

  • 0

Greetings.

I’m looking for a way to parse a number of XML files in a particular directory with ASP.NET (C#). I’d like to be able to return content from particular elements, but before that, need to find those that have a certain value between an element.

Example XML file 1:

<file>     <title>Title 1</title>     <someContent>Content</someContent>     <filter>filter</filter> </file> 

Example XML file 2:

<file>     <title>Title 2</title>     <someContent>Content</someContent>     <filter>filter, different filter</filter> </file> 

Example case 1:

Give me all XML that has a filter of ‘filter’.

Example case 2:

Give me all XML that has a title of ‘Title 1’.

Looking, it seems this should be possible with LINQ, but I’ve only seen examples on how to do this when there is one XML file, not when there are multiples, such as in this case.

I would prefer that this be done on the server-side, so that I can cache on that end.

Functionality from any version of the .NET Framework can be used.

Thanks!

~James

  • 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-10T15:04:49+00:00Added an answer on May 10, 2026 at 3:04 pm

    If you are using .Net 3.5, this is extremely easy with LINQ:

    //get the files XElement xe1 = XElement.Load(string_file_path_1); XElement xe2 = XElement.Load(string_file_path_2);  //Give me all XML that has a filter of 'filter'. var filter_elements1 = from p in xe1.Descendants('filter') select p; var filter_elements2 = from p in xe2.Descendants('filter') select p; var filter_elements = filter_elements1.Union(filter_elements2);  //Give me all XML that has a title of 'Title 1'. var title1 = from p in xe1.Descendants('title') where p.Value.Equals('Title 1') select p; var title2 = from p in xe2.Descendants('title') where p.Value.Equals('Title 1') select p; var titles = title1.Union(title2); 

    This can all be written shorthand and get you your results in just 4 lines total:

    XElement xe1 = XElement.Load(string_file_path_1); XElement xe2 = XElement.Load(string_file_path_2); var _filter_elements = (from p1 in xe1.Descendants('filter') select p1).Union(from p2 in xe2.Descendants('filter') select p2); var _titles = (from p1 in xe1.Descendants('title') where p1.Value.Equals('Title 1') select p1).Union(from p2 in xe2.Descendants('title') where p2.Value.Equals('Title 1') select p2); 

    These will all be IEnumerable lists, so they are super easy to work with:

    foreach (var v in filter_elements)     Response.Write('value of filter element' + v.Value + '<br />'); 

    LINQ rules!

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

Related Questions

Loading...

Sidebar

Ask A Question

Stats

  • Questions 55k
  • Answers 55k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer This will result in undefined behavior, which means it may… May 11, 2026 at 7:36 am
  • added an answer Try calling ChangeDatabase on your connection. MSDTC will always be… May 11, 2026 at 7:36 am
  • added an answer In MS SQL and Oracle: SELECT * FROM ( SELECT… May 11, 2026 at 7:36 am

Top Members

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

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.