NAME

XML::SemanticDiff - Perl extension for comparing XML documents' abstract structure and contents.

SYNOPSIS

use XML::SemanticDiff;
my $diff = XML::SemanticDiff->new();

foreach my $change ($diff->compare($file, $file2)) {
    print "$change->{message} in context $change->{context}\n";
}

# or, if you want line numbers:

my $diff = XML::SemanticDiff->new(keeplinenums => 1);

foreach my $change ($diff->compare($file, $file2)) {
    print "$change->{message} (between lines $change->{startline} and $change->{endline})\n";
}

DESCRIPTION

XML::SematicDiff provides a way to compare the contents and structure of two XML documents. By default, it returns a list of hashrefs where each hashref describes a single difference between the two docs.

METHODS

$obj->new([%options])

Ye olde object constructor.

The new() method recognizes the following options:

  • keeplinenums

    When this option is enabled XML::SemanticDiff will add the 'startline' and 'endline' properties (containing the line numbers for the reported element's start tag and end tag) to each warning. For attribute events these numbers reflect the start and end tags of the element which contains that attribute.

  • keepdata

    When this option is enabled XML::SemanticDiff will add the 'old_value' and 'new_value' properties to each warning. These properties contain, surprisingly, the old and new values for the element or attribute being reported.

    In the case of missing elements or attributes (those in the first document, not in the second) only the 'old_value' property will be defined. Similarly, in the case of rogue elements or attributes (those in the second document but not in the first) only the 'new_value' property will be defined.

    Note that using this option will greatly increase the amount of memory used by your application.

  • diffhandler

    Taking a blessed object as it's sole argument, this option provides a way to hook the basic semantic diff engine into your own custom handler class.

    Please see the section on 'CUSTOM HANDLERS' below.

CUSTOM HANDLERS

Internally, XML::SemanticDiff uses an event-based model somewhat reminscent of SAX2 where the various 'semantic diff events' are handed off to a seperate handler class to cope with the details. For most general cases where the user only cares about reporting the differences between two docs, the default handler, XML::SemanticDiff::BasicHandler, will probably suffice. However, it is often desirable to add side-effects to the diff process (updating datastores, widget callbacks, etc.) and a custom handler allows you to be creative with what to do about differences between two XML documents and how those differences are reported through the compare() method.

BETA WARNING more docs needed here. For now, look at the code in XML::SemainticDiff::BasicHandler and the distribution's test files for examples.

Note that if a given method is not implemented in your custom handler class, XML::SemanticDiff will not complain; but it means that all of those events will be silently ignored. Consider yourself warned.

AUTHOR

Kip Hampton, khampton@totalcinema.com

COPYRIGHT

Copyright (c) 2000 Kip Hampton. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

SEE ALSO

perl(1).