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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T03:29:43+00:00 2026-05-11T03:29:43+00:00

I have two documents both are similar but I need to find an elegant

  • 0

I have two documents both are similar but I need to find an elegant and efficient way to compare the two files and return the values in Doc #1 that don’t exist in Doc #2.

XML Doc #1

      <ids>         <id>1</id>         <id>2</id>         <id>5</id>         <id>6</id>         <id>7</id>         <id>8</id>         <id>9</id>        </ids>     </ids> 

XML Doc #2

  <ids>     <id>1</id>     <id>2</id>     <id>7</id>     <id>8</id>     <id>9</id>   </ids> 

I was thinking about using linq if I could join these two documents on the id field. Is there a better way? I’m looking to return id #s 5 and 6.

  • 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-11T03:29:43+00:00Added an answer on May 11, 2026 at 3:29 am

    Here is a sample that I know works, I only tried it out with small files (File1.xml had 20 items, File2.xml 8 items).

    XDocument file1Doc = XDocument.Load('File1.xml'); XDocument file2Doc = XDocument.Load('File2.xml');  IEnumerable<string> file1Elements = from d in file1Doc.Descendants('Id')                                     select d.Value;  IEnumerable<string> file2Elements = from d in file2Doc.Descendants('Id')                                     select d.Value;  var difference = file1Elements.Except(file2Elements); 

    Alternatively, and likely more inline with what you seek is:

    XDocument file1Doc = XDocument.Load('File1.xml'); XDocument file2Doc = XDocument.Load('File2.xml');  IEnumerable<string> file2Elements = from d in file2Doc.Descendants('Id')                                     select d.Value;  var x = from include in file1Doc.Descendants('Id')         where file2Elements.Contains(include.Value) != true         select include; 

    You might also find some help looking at 101 LINQ Samples on MSDN.

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

Sidebar

Related Questions

I have two XmlDocuments that both have a namespace attribute specified. Both documents have
So I have two documents that both have allot of properties. One document is
I have two types of text that need to follow similar coloring rules based
I have two documents, a .docx and an .xlsx both are in the same
Suppose I have two documents that are identical except the lines are shuffled. Is
I have a loop that calculates the similarity between two documents. It collects all
I have used two GUIDs to open the folders My Computer and My Documents
I have a mongo collection which has documents with two fields fieldA and fieldB,
this is my situation: I have two org.w3c.dom.Document created from two xml files. What
I have some code where I need two separate required field validators for one

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.