Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (7)
As of 2021-05-12 10:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Perl 7 will be out ...





    Results (126 votes). Check out past polls.

    Notices?