Forum Discussion
jos07
Feb 01, 2022Copper Contributor
How to compare two xml files and display the difference side by side.
$baseServer="C:\Store\PS\referrencexml.xml" $Server2Compare="C:\Store\PS\differencexml.xml" $boutput = Compare-Object -ReferenceObject (Get-Content -Path "$baseServer") -DifferenceObject (Get-Conte...
Jonathan_Allen
Feb 01, 2022Brass Contributor
PowerShell Compare-Object is giving you a text comparison line-by-line of the files that you have passed it, so sees one line in the reference object and a different line in the difference object - it isn't aware that they are the same part of the xml and that the value is the difference.
Is this comparison a one-off or something you need to repeat/automate? If its a one off then perhaps a text editor like VSCode or Notepadd++ will let you compare the files ?
If you need to automate then I think you might need to think beyond XML so that the descriptive structure of the data is not being compared - perhaps as a csv file or something. Can you share more of the xml, is it very complex?
Is this comparison a one-off or something you need to repeat/automate? If its a one off then perhaps a text editor like VSCode or Notepadd++ will let you compare the files ?
If you need to automate then I think you might need to think beyond XML so that the descriptive structure of the data is not being compared - perhaps as a csv file or something. Can you share more of the xml, is it very complex?
- jos07Feb 02, 2022Copper ContributorThanks for your reply Jonathan.
It's not a one time thing, I have to repeat this validation also automate it. As you presumed it's a complex XML. Even I tried with comparing JSON files, but again I'm ending at the same problem, it's just compare-object function not able to print the output difference side by side, and i'm not aware of how to do it in alternate way or customized way.