user1040466
user1040466

Reputation:

How can I compare two XML files for their differences?

I want to compare two xml raw files and capture their differences in data. For example,

    <Segment>
      <SegNum>2</SegNum>
      <Dt>20110910</Dt>
      <Comment>B test</Comment>
    </Segment>
  </Retrieve>
</info>

File B:

<info>
  <Retrieve>
    <LastNameInfo>
      <LNameNum>2</LNameNum>
      <NameType/>
      <LName>TESTING</LName>
    </LastNameInfo>
    <Segment>
      <SegNum>1</SegNum>
      <Status>HS</Status>
      <Comment>A test</Comment>
    </Segment>
    <Segment>
      <SegNum>2</SegNum>
      <Dt>20110</Dt>
      <Comment>COULD I USE LINQ</Comment>
    </Segment>
  </Retrieve>
</info>

so the output i need should be a file with just the differences like

              <LNameNum>1</LnameNum> File 2:<Lnamenum>2</Lnamenum>

Upvotes: 2

Views: 2689

Answers (2)

Devdutt Patnaik
Devdutt Patnaik

Reputation: 71

I've used the XmlDiff class in the past. At last check, it still works with framework 4.0. http://msdn.microsoft.com/en-us/library/aa302295.aspx

Upvotes: 0

Daniel Pratt
Daniel Pratt

Reputation: 12077

There is a library (and tool), XML Diff and Patch, published to MSDN a while back that does this.

Upvotes: 2

Related Questions