XML::S...ticDiff(3pm)
okay bestie, welcome to the XML::S...ticDiff(3pm) page from User Contributed Perl Documentation β weβre talking about XML::SemanticDiff, and yes, the header is out here looking like a glitchy text from your worstie. Stay with me, itβs lowkey iconic.
πΈ NAME πΈ
XML::SemanticDiff β a Perl extension for comparing XML documents.
π VERSION π
version 1.0007
π 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 π¦
So XML::SematicDiff β spelling exactly as the description says it, bestie β 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. Itβs giving βspot the differenceβ but for XML, and honestly the vibes are immaculate.
π VERSION π (yes, itβs listed twice, and we respect that)
version 1.0007
π οΈ METHODS π οΈ
π $obj->new([%options]) π
The classic object constructor. Ye olde one, as the manpage says. new() recognizes these options:
keeplinenumsβ turn this on andXML::SemanticDiffadds the'startline'and'endline'properties to each warning. Those contain the line numbers for the reported elementβs start tag and end tag. For attribute events, these numbers reflect the start and end tags of the element that contains that attribute.keepdataβ turn this on andXML::SemanticDiffadds the'old_value'and'new_value'properties to each warning. These contain, surprisingly, the old and new values for the element or attribute being reported. For missing elements or attributes (those in the first document, not in the second), only the'old_value'property will be defined. Similarly, for 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. Thatβs the tradeoff, bestie.diffhandlerβ takes a blessed object as its sole argument. This option gives you a way to hook the basic semantic diff engine into your own custom handler class. Please see the section on'CUSTOM HANDLERS'below.ignorexpathβ takes an array of strings as argument. The strings are interpreted as simple xpath expressions. Nodes matching these expressions are ignored during comparison. All xpath expressions should be absolute (start with/). Current implementation ignores namespaces during comparison.
π @results = $differ->compare($xml1, $xml2) π
Compares the XMLs $xml1 and $xml2. $xml1 and $xml2 can be:
- filenames β this will be considered if it is a string that does not contain newlines and exists in the filesystem.
- the XML text itself β this will be considered if itβs any kind of string.
- the results of
read_xml()(see below) β this will be considered if itβs a hash reference.
π 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 HANDLERS π«
Internally, 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 METHODS π
Hereβs the list of handler methods you can use for your custom diff-handler class. Main character energy only.
π¦ init($self, $diff_obj) π¦
The init method is called immediately before the two document HASHes are compared. The blessed XML::SemanticDiff object is passed as the sole argument, so any values 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 the 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 in 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 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 its 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.
π AUTHOR π
Originally by Kip Hampton, khampton@totalcinema.com.
Further Maintained by Shlomi Fish, http://www.shlomifish.org/.
βοΈ 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.
Shlomi Fish hereby disclaims any implicit or explicit copyrights on this software.
π LICENSE π
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
π SEE ALSO π
π― AUTHORS π―
- Shlomi Fish <
shlomif@cpan.org> - Chris Prather <
chris.prather@tamarou.com>
Β©οΈ COPYRIGHT AND LICENSE Β©οΈ
This 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.
π BUGS π
Please 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.
π«Ά SUPPORT π«Ά
Perldoc
You can find documentation for this module with the perldoc command.
perldoc XML::SemanticDiff
Websites
The 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.
- MetaCPAN β a modern, open-source CPAN search engine, useful to view POD in HTML format.
https://metacpan.org/release/XML-SemanticDiff - Search CPAN β the default CPAN search engine, useful to view POD in HTML format.
http://search.cpan.org/dist/XML-SemanticDiff - RT: CPANβs Bug Tracker β the RT (Request Tracker) website is the default bug/issue tracking system for CPAN.
https://rt.cpan.org/Public/Dist/Display.html?Name=XML-SemanticDiff - AnnoCPAN β the AnnoCPAN is a website that allows community annotations of Perl module documentation.
http://annocpan.org/dist/XML-SemanticDiff - CPAN Ratings β the CPAN Ratings is a website that allows community ratings and reviews of Perl modules.
http://cpanratings.perl.org/d/XML-SemanticDiff - CPANTS β the CPANTS is a website that analyzes the Kwalitee (code metrics) of a distribution.
http://cpants.cpanauthors.org/dist/XML-SemanticDiff - CPAN Testers β the CPAN Testers is a network of smoke testers who run automated tests on uploaded CPAN distributions.
http://www.cpantesters.org/distro/X/XML-SemanticDiff - CPAN Testers Matrix β the CPAN Testers Matrix is a website that provides a visual overview of the test results for a distribution on various Perls/platforms.
http://matrix.cpantesters.org/?dist=XML-SemanticDiff - CPAN Testers Dependencies β the CPAN Testers Dependencies is a website that shows a chart of the test results of all dependencies for a distribution.
http://deps.cpantesters.org/?module=XML::SemanticDiff
Bugs / Feature Requests
Please 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 Code
The 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
Thatβs the whole XML::S...ticDiff(3pm) page, bestie π
β¨ The footer says perl v5.42.0, 2018-08-16, and XML::S...ticDiff(3pm) β so you know exactly what era of manpage chaos youβre living in π«ΆπΈ
π¦ where this page comes from
- opensuse-leap 16.0: perl-XML-SemanticDiff 1.0007-bp160.1.4 Β· Artistic-1.0 OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms