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

hi,

I am relatively new, but I have spent some time on this issue, so any help would be appreciated. I am using XML::Parser to parse my XML documents. I have set up my handlers and it all works beautifully.

I then want to use XML::SemanticDiff to compare my XML documents. This works as well, but I'd like to setHandlers for this to catch rogue_element for example. The code I am using is just the snipet for CPAN.

my $diff = XML::SemanticDiff->new(); foreach my $change ($diff->compare($file, $file2)) { print "$change->{message} in context $change->{context}\n"; }
To set the handlers I am appying the same logic I used for my parser, so I end up with something like this, but I keep getting various errors.

my $diff = new XML::SemanticDiff->new(keepdata); $diff->setHandlers(rogue_element => \&rogueElement); $diff->compare($xmlToday,$xmlYesterday)); sub rogueElement{ print "something\n"; }
Am I on the right track here?

Edited by thelenm: added <code> tags

Replies are listed 'Best First'.
Re: setHandlers for XML::SemanticDiff
by bobn (Chaplain) on Jul 20, 2003 at 19:13 UTC

    The doc for XML::SemanticDiff shows no setHandlers method. XML::Parser is used but not inherited from in this package, near as I can tell.

    The doc does show a diffhandler option to new(), which would apparently be used as:

    #!/usr/bin/perl -w my $h = Myclass->new; use XML::SemanticDiff; my $diff = XML::SemanticDiff->new(diffhandler => $h); $diff->compare( qw(1.xml 2.xml)); package Myclass; use Data::Dumper; sub new { bless {}, shift } sub rogue_element { my ( $self, $name, $props ) = @_; print "Something\n"; print "Element name is: $name\n"; print Dumper($props); }

    Updated with correct code.

    --Bob Niederman, http://bob-n.com
Re: setHandlers for XML::SemanticDiff
by bobn (Chaplain) on Jul 20, 2003 at 19:52 UTC

    For the future, here are 2 hints:

    Post the error messages with your question.

    Read the error messages and try to understand them first.

    In theis case, the message Can't locate object method "setHandlers" via package "XML::SemanticDiff" is clearly telling you that the setHandlers method does not exisin inXML::SemanticDiff or anything it inherits from.



    --Bob Niederman, http://bob-n.com