Comparing 2 XML Files using PHP

I want to compare 2 big xml files and retrieve the differences. Like ExamXML and DiffDog do. The solution I found was cycling through all child nodes of each file simultaneously and check if they are equal. But I have no idea how to achieve that... How can I loop through all child nodes and their properties? How can I check if the first element of the first file is equal to the first element of the second file, the second element of the first file is equal to the second element of the second file and so on?

Do yo have a better idea to compare 2 xml files?


Have you looked at using XPath at all? Seems like an easy way to grab all of the child nodes. Then you'd be able to loop through the nodes and compare the attributes/textContent.

This might be a very alternative solution for you but this is how I would do it.

First, I'd try to get the format into something much more manageable like an array so I would convert the XML to an array.

This is some simple code to do just that.

Then PHP has an array_diff() function that can show you the differences.

This may or may not work for you considering what you need to do with the differences but if you're looking to just identify and act upon them this might be a very quick solution to your problem.

I was looking for something to compare two XML like you, and I found this solution that works very well.

I hope that helps to someone.

Need Your Help

add class to table row when glyhicon is clicked

jquery css addclass glyphicons

Ok so here it is I have no clue where to go next or how this works so any help will be awsome I want know how to add a class "success" to a table row when A glyphicon is cliked here's my fiddle

Jquery/ PHP Show database after got updated

php jquery

I have this jQuery which updates the DB on blur. It works fine except I want the code to show the current DB value after it got updated. There is a value in the database the amount in the field wil...