• Post Reply Bookmark Topic Watch Topic
  • New Topic

Java Program to find diff between two xml files  RSS feed

 
Nidheesh Krishna
Ranch Hand
Posts: 62
Java MySQL Database Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
i have two xml files and i need to change first xml file based on the differences found in second xml file.

file1.xml

file2.xml


i need to perform this action using java code

 
SunilK Chauhan
Ranch Hand
Posts: 64
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Nidheesh Krishna,

I have one solution which i had already used in my application.
click the link given below to get it with all details.

https://docs.oracle.com/database/121/ADXDK/adx_j_diff.htm#ADXDK205

Regards,
Sunil Chauhan
 
Nidheesh Krishna
Ranch Hand
Posts: 62
Java MySQL Database Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hai SunilK Chauhan, i need to write changes in one xml to another, not to display the difference
 
Stephan van Hulst
Saloon Keeper
Posts: 7993
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Nidheesh, welcome to CodeRanch!

The next time you post code, please use code tags. I've added them for you this time.

As for your issue, you haven't explained how the differences should affect anything. What result do you expect? What have you tried so far to achieve the result?
 
Nidheesh Krishna
Ranch Hand
Posts: 62
Java MySQL Database Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i need a new file1.xml with changes in node values as shown in file2.xml. i tried XMLUNIT based checking of xml files, but it shows only the difference between xml files,it does not provide methods to write changes
 
Stephan van Hulst
Saloon Keeper
Posts: 7993
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Again, you didn't explain how the changes should be incorporated.

I'm assuming you don't want file1.xml to look exactly the same as file2.xml, because then you can just copy the file.
 
Nidheesh Krishna
Ranch Hand
Posts: 62
Java MySQL Database Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
during running of the java code, i need to check two files in the order of node by node, and if any value changes found in file1, just write that change to file1
 
Stephan van Hulst
Saloon Keeper
Posts: 7993
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So you want file 1 to be a copy of file 2.
 
Nidheesh Krishna
Ranch Hand
Posts: 62
Java MySQL Database Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
suppose the file1 is

and file2 is,

then copy operation of files will remove <pages>2</pages> from file1. i want to preserve thos value and also changes should be affect in file1
 
Joe Harry
Ranch Hand
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Two things:

1. You would be doing a great help to yourself by showing us what you have tried so far rather than asking someone for code.

2. Please make use of the code tags when you post content that contains source code, xml etc.,

To me this seems to be a trivial exercise that should be doable by any beginner. Just show us what you have tried so far!
 
Stephan van Hulst
Saloon Keeper
Posts: 7993
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is actually not a very trivial problem. What if you have a list of elements?
Are you going to merge things with the same id? Are you going to add new things? A lot of these issues can not be solved easily without having a good clear specification of the problem.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!