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

Re: XML compare with a key

by hdb (Monsignor)
on Apr 02, 2019 at 12:36 UTC ( #1232001=note: print w/replies, xml ) Need Help??

in reply to XML compare with a key

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.

Replies are listed 'Best First'.
Re^2: XML compare with a key
by haukex (Archbishop) on Apr 02, 2019 at 12:40 UTC

      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

        For such simple stuff the module is still useful.

        I agree that the module can still be used for very simple cases, like reading simple config files in a known format (Update: although there are better modules available, such as XML::Rules). However, we don't know if the OP's actual XML really is as simple as the example shown in the root node, therefore whether it will work at all (see code below), and you also didn't mention any of the major caveats associated with that module, which is why I posted my comment.

        use warnings; use strict; use Data::Dump; use XML::Simple qw/:strict XMLin/; dd XMLin('<root><x><y>Foo</y></x></root>',ForceArray=>[],KeyAttr=>[]); dd XMLin('<root><x y="Foo"></x></root>', ForceArray=>[],KeyAttr=>[]); __END__ { x => { y => "Foo" } } { x => { y => "Foo" } }

Log In?

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (6)
As of 2023-12-06 17:16 GMT
Find Nodes?
    Voting Booth?
    What's your preferred 'use VERSION' for new CPAN modules in 2023?

    Results (31 votes). Check out past polls.