|
NAMEXML::SemanticDiff - Perl extension for comparing XML documents.VERSIONversion 1.0007SYNOPSISuse 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"; } DESCRIPTIONXML::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.VERSIONversion 1.0007METHODS$obj->new([%options])Ye olde object constructor.The new() method recognizes the following options:
@results = $differ->compare($xml1, $xml2)Compares the XMLs $xml1 and $xml2 . $xml1 and $xml2 can be:
my $doc = read_xml($xml_location)This will read the XML, process it for comparison and return it. See compare() for how it is determined.CUSTOM HANDLERSInternally, XML::SemanticDiff uses an event-based model somewhat reminiscent of SAX where the various 'semantic diff events' are handed off to a separate 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 back to the application through the compare() method.HANDLER METHODSThe following is a list of handler methods that can be used for your custom diff-handler class.init($self, $diff_obj)The "init" method is called immediately before the the two document HASHes are compared. The blessed XML::SemanticDiff object is passed as the sole argument, so any values that you wish to pass from your application to your custom handler can safely be added to the call to XML::SemanticDiff's constructor method.rogue_element($self, $element_name, $todoc_element_properties)The "rogue_element" method handles those cases where a given element exists in the to-file but not in the from-file.missing_element($self, $element_name, $fromdoc_element_properties)The "missing_element" method handles those cases where a given element exists in the from-file but not in the to-file.element_value($self, $element, $to_element_properties, $fromdoc_element_properties)The "element_value" method handles those cases where the text data differs between two elements that have the same name, namespace URI, and are at the same location in the document tree. Note that all whitespace is normalized and the text from mixed-content elements (those containing both text and child elements mixed together) is aggregated down to a single value.namespace_uri($self, $element, $todoc_element_properties, $fromdoc_element_properties)The "namespace_uri" method handles case where the XML namespace URI differs between a given element in the two documents. Note that the namespace URI is checked, not the element prefixes since <foo:element/> <bar:element/> and <element/> are all considered equivalent as long as they are bound to the same namespace URI.rogue_attribute($self, $attr_name, $element, $todoc_element_properties)The "rogue_attribute" method handles those cases where an attribute exists in a given element the to-file but not in the from-file.missing_attribute($self, $attr_name, $element, $todoc_element_properties, $fromdoc_element_properties)The "missing_attribute" method handles those cases where an attribute exists in a given element exists in the from-file but not in the to-file.attribute_value($self, $attr_name, $element, $todoc_element_properties, $fromdoc_element_properties)The "attribute_value" method handles those cases where the value of an attribute varies between the same element in both documents.final($self, $diff_obj)The "final" method is called immediately after the two document HASHes are compared. Like the "init" handler, it is passed a copy of the XML::SemanticDiff object as it's sole argument.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. AUTHOROriginally by Kip Hampton, khampton@totalcinema.com .Further Maintained by Shlomi Fish, <http://www.shlomifish.org/> . COPYRIGHTCopyright (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.Shlomi Fish hereby disclaims any implicit or explicit copyrights on this software. LICENSEThis program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.SEE ALSOperl(1).AUTHORS
COPYRIGHT AND LICENSEThis software is copyright (c) 2001 by Kip Hampton.This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. BUGSPlease report any bugs or feature requests on the bugtracker website <https://github.com/shlomif/perl-XML-SemanticDiff/issues>When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature. SUPPORTPerldocYou can find documentation for this module with the perldoc command.perldoc XML::SemanticDiff WebsitesThe following websites have more information about this module, and may be of help to you. As always, in addition to those websites please use your favorite search engine to discover more resources.
Bugs / Feature RequestsPlease report any bugs or feature requests by email to "bug-xml-semanticdiff at rt.cpan.org", or through the web interface at <https://rt.cpan.org/Public/Bug/Report.html?Queue=XML-SemanticDiff>. You will be automatically notified of any progress on the request by the system.Source CodeThe code is open to the world, and available for you to hack on. Please feel free to browse it and play with it, or whatever. If you want to contribute patches, please send me a diff or prod me to pull from your repository :)<https://github.com/shlomif/perl-XML-SemanticDiff> git clone git://github.com/shlomif/perl-XML-SemanticDiff.git
Visit the GSP FreeBSD Man Page Interface. |