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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T12:45:26+00:00 2026-05-24T12:45:26+00:00

I know you can check if all elements from one list exist in another

  • 0

I know you can check if all elements from one list exist in another list like this (from another post here):

bool result = list.All(x => dataList.Contains(x));

But how do I check if all elements exist in another list have the same “subvalue”?

I have two xml documents _mapdoc and _mapdocCopy, and I want to compare all <file> elements where the attribute path are all found in the other xml document.

So I started doing something similar to above:

if (_mapdocCopy.Descendants("file").All(x => _mapdoc.Descendants("file").Contains(x)))

But I immediately realized that this would compare the entire <file> elements, and they will often not be the same (they may have different sub elements), even if their “path” attribute have the same values. And it’s only this I want to test for.

I also (in a different context) want to be able to get the one’s that are not the same (still with regards to the path attribute only), so help with that would also be appreciated. But it’s a different question, I still need the Linq query above.

Any ideas?

  • 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-24T12:45:27+00:00Added an answer on May 24, 2026 at 12:45 pm

    I’d think along the lines of replacing the .Contains with .Any(appropriate condition). Something like:

    if (_mapdocCopy.Descendants("file").All(
            x => _mapdoc.Descendants("file").Any(y => y.path == x.path)))
    

    Edit: Ad second part, the brute force approach is:

    ... = _mapdocCopy.Descendants("file").Where(
            x => !_mapdoc.Descendants("file").Any(y => y.path == x.path)))
    

    (take those that don’t exist in the other set — note that the closure is negated). However there is also Except linq method. I am not sure I’ve got correct syntax, but it would be something like:

    ... = _mapdocCopy.Descendants("file").Except(
            _mapdoc.Descendants("file"),
            (x, y) => x.path == y.path)
    

    (except where I am not sure whether the closure will convert to IEqualityComparer or needs some extra hackery for it)

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

Sidebar

Related Questions

Does anyone know how I can check to see if a directory is writeable
Does anyone know of a utility that can check whether a HTTP request/response is
As you know, in Eclipse you can turn on Unnecessary 'else' statement check that
This is something I know can be done somehow , because I've done it
I know I can do most of this by hacking Trac and using Git
I have `a string example = this site holds all the examples from The
I just need a sanity check here... DEMO Basically, I can't figure out how
First off: I know that this isn't reliable for actually checking if I can
I'm thinking of an approach something like this. Please let me know if this
Can someone explain why the HashMap acts like it does in this example: Simple

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.