http://qs321.pair.com?node_id=1232001


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" } }