Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

XML compare with a key

by PiyaPerl (Acolyte)
on Apr 02, 2019 at 11:51 UTC ( #1232000=perlquestion: print w/replies, xml ) Need Help??

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

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1232000]
Approved by Corion
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (3)
As of 2022-05-25 00:34 GMT
Find Nodes?
    Voting Booth?
    Do you prefer to work remotely?

    Results (84 votes). Check out past polls.