http://www.perlmonks.org?node_id=1232000

PiyaPerl has asked for the wisdom of the Perl Monks concerning the following question:

Hello all, I need an input that if I have 2 XML files which I need to compare like below :
<xml top> <xml body> <tag1>jdjdjdjd</tag1> <tag2>dkdkkd</tag2> </xml body> </xmltop> and second file like <xml top> <xml body> <tag2>jdjdjdjd</tag2> <tag1>ghghgh</tag1> </xml body> </xmltop>
So basically the order is different but i want o simply set a key and compare like for like.

Replies are listed 'Best First'.
Re: XML compare with a key
by hdb (Monsignor) on Apr 02, 2019 at 12:36 UTC

    As one option, you could use XML::Simple to translate both your xml strings into hash references and then walk through both of them to spot the differences. You could also use a module that does it for you, for example XML::Diff or XML::SemanticDiff.

        I am getting tired by being pointed to this comment each and every time. For such simple stuff the module is still useful.

        And anyways, the OP will reply that (s)he does not want to install any module, see earlier questions... Re^4: XML file difference highlights