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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:27:51+00:00 2026-05-22T01:27:51+00:00

Is there any way to compare two XML files in C#? I only want

  • 0

Is there any way to compare two XML files in C#? I only want to compare the nodes of the first file with that of of second file. I don’t want to append the missing nodes.

Is there any way to do this?

Here’s what I have tried:

var docA = XDocument.Parse(@"<mind_layout></mind_layout>");
var docB = XDocument.Parse(@"<mind_layout></mind_layout>");

var rootNameA = docA.Root.Name;
var rootNameB = docB.Root.Name;
var equalRootNames = rootNameB.Equals(rootNameA);

var descendantsA = docA.Root.Descendants();
var descendantsB = docB.Root.Descendants();
for (int i = 0; i < descendantsA.Count(); i++)
{
    var descendantA = descendantsA.ElementAt(i);
    var descendantB = descendantsB.ElementAt(i);
    var equalChildNames = descendantA.Name.Equals(descendantB.Name);

    var valueA = descendantA.Value;
    var valueB = descendantA.Value;
    var equalValues = valueA.Equals(valueB);
}

where <mind_layout> is the root node in both the files.

  • 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-22T01:27:52+00:00Added an answer on May 22, 2026 at 1:27 am

    If you just want to compare the file contents (including, for example, indentation), you coud do:

    if (File.ReadAllText(@"C:\path\to\file1.xml") == File.ReadAllText(@"C:\path\to\file2.xml"))
    {
        // Same TEXT content
    }
    

    (Warning: this is not the most optimized check you could do!)

    If you want to compare the XML content (regardless of the formatting), you can do:

    var doc1 = XDocument.Load(File.OpenRead(@"C:\path\to\file1.xml"));
    var doc2 = XDocument.Load(File.OpenRead(@"C:\path\to\file2.xml"));
    
    if (XDocument.DeepEquals(doc1, doc2))
    {
        // Same XML content
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any way to compare two functions in Haskell? My thought is that
Is there any way to programatically compare two sound files to determine if they
I'm trying to compare two Xml files using C# code. I want to ignore
Is there any way find difference between two cs files. I already ask question
Is there any way to compare two strings in SQL Server 2008 stored procedure
Is there any way to compare two vectors? if (vector1 == vector2) DoSomething(); Note:
I have to compare XML data. There are two sources- Web Service XML files
Is there any way to compare two list of strings(regardless of case sensitivity) or
In java is there any elegant way to compare two different StringBuilders and copy
Is there any way to compare lines of code between two clearcase versions ,

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.