XML-SemanticDiff-1.0000000755000765000765 011233530415 14544 5ustar00shlomishlomi000000000000Changes000444000765000765 536111233530415 16122 0ustar00shlomishlomi000000000000XML-SemanticDiff-1.0000Revision history for Perl extension XML::SemanticDiff. 1.0000 July 28 2009 - Fixed the POD displaying: - https://rt.cpan.org/Ticket/Display.html?id=48259 0.99 October 03 2008 - Now can exclude some paths from the comparison: - http://rt.cpan.org/Ticket/Display.html?id=39705 0.98 September 13 2008 - Added the LICENSE section to the POD (Kwalitee). - Added the "use warnings" (Kwalitee). - Added the "Repository URL" on the resources page. 0.97 August 08 2007 - Added the README (Kwalitee) - Specified the LICENSE (as "perl") explicitly in the Makefile.PL. (Kwalitee) - Added t/pod.t. (Kwalitee). - fixed the POD in the process. - Created a Build.PL script based on the Makefile.PL in order to make sure the META.yml is according to the SPEC. (Kwalitee). - Added the t/pod-coverage.t file and made sure the files have full POD coverage. (Kwalitee) - Made sure the second argument in compare can accept a processed XML result, and refactored the code in the process. Added the t/13to-doc-read.t test file. - Converted the "PathFinder" package in lib/XML/SemanticDiff.pm to "XML::SemanticDiff::PathFinder" to maintain namespace purity. - Converted the Pkg to use an object using Non-Expat-Options. Made the global variables as class members using accessors. 0.96 July 03 2007 - Fixed the warning emitted with the namespaces being undefined. (t/8nonexist_ns.t) - fixes http://rt.cpan.org/Public/Bug/Display.html?id=1379 - Fixed the search algorithm so it will identify the location of the XML tags properly. (t/09two-tags.t) - Applied a modified version of: http://rt.cpan.org/Ticket/Display.html?id=24715 - Fixes an exception when comparing XML with multi-byte characters. - Thanks to RMBARKER - t/10wide-chars.t - Applied a modified version of: http://rt.cpan.org/Ticket/Display.html?id=18491 - Fixes a case where the same tags in different places with identical contents, are not considered semantically identical. - Thanks to CLOTHO for reporting it and suggesting a fix. - t/11tag-in-different-locations.t - Added a regression test against bug: http://rt.cpan.org/Ticket/Display.html?id=2322 - Seems to already have been fixed. - t/12missing-element-has-o-as-cdata.t 0.95 April 09 2002 [ Undocumented changelog. ] 0.93 June 14 2001 - third (hopefully final) BETA - more doc fixes. 0.91 June 12 2001 - second BETA release. - code cleanup. - major doc fixes. 0.50 May 25 2001 - initial public BETA release. 0.01 Thu May 24 10:09:38 2001 - original version; created by h2xs 1.19 MANIFEST000444000765000765 105211233530415 15751 0ustar00shlomishlomi000000000000XML-SemanticDiff-1.0000Build.PL Changes eg/camelids2.xml eg/camelids.xml eg/xmlsemdiff lib/XML/SemanticDiff/BasicHandler.pm lib/XML/SemanticDiff.pm Makefile.PL MANIFEST META.yml Module meta-data (added by MakeMaker) README t/01basic.t t/02load_xml.t t/03simple_compare.t t/04namespaces.t t/05simple_handler.t t/06pass_to_handler.t t/07pitest.t t/08nonexist_ns.t t/09two-tags.t t/10wide-chars.t t/11tag-in-different-locations.t t/12missing-element-has-o-as-cdata.t t/13to-doc-read.t t/14ignore_xpath.t t/15ignore_multi.t t/pod-coverage.t t/pod.t META.yml000444000765000765 145311233530415 16076 0ustar00shlomishlomi000000000000XML-SemanticDiff-1.0000--- name: XML-SemanticDiff version: 1.0000 author: - 'Kip Hampton ' abstract: Perl extension for comparing XML documents. license: perl resources: Repository: http://svn.berlios.de/svnroot/repos/web-cpan/XML-SemanticDiff/ requires: Digest::MD5: 0 Encode: 0 XML::Parser: 0 perl: 5.006 configure_requires: Module::Build: 0.34 provides: XML::SemanticDiff: file: lib/XML/SemanticDiff.pm version: 1.0000 XML::SemanticDiff::BasicHandler: file: lib/XML/SemanticDiff/BasicHandler.pm version: 0.94 XML::SemanticDiff::PathFinder: file: lib/XML/SemanticDiff.pm XML::SemanticDiff::PathFinder::Obj: file: lib/XML/SemanticDiff.pm generated_by: Module::Build version 0.34 meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: 1.4 Makefile.PL000444000765000765 101611233530415 16572 0ustar00shlomishlomi000000000000XML-SemanticDiff-1.0000# Note: this file was auto-generated by Module::Build::Compat version 0.34 require 5.006; use ExtUtils::MakeMaker; WriteMakefile ( 'NAME' => 'XML::SemanticDiff', 'VERSION_FROM' => 'lib/XML/SemanticDiff.pm', 'PREREQ_PM' => { 'Digest::MD5' => '0', 'Encode' => '0', 'XML::Parser' => '0' }, 'INSTALLDIRS' => 'site', 'EXE_FILES' => [], 'PL_FILES' => {} ) ; Build.PL000444000765000765 130011233530415 16110 0ustar00shlomishlomi000000000000XML-SemanticDiff-1.0000use strict; use warnings; use Module::Build; my $builder = Module::Build->new( module_name => 'XML::SemanticDiff', license => 'perl', dist_author => 'Kip Hampton ', dist_version_from => 'lib/XML/SemanticDiff.pm', requires => { 'Encode' => '0', 'Digest::MD5' => '0', 'perl' => '5.006', 'XML::Parser' => '0', }, add_to_cleanup => [ 'XML-SemanticDiff-*' ], create_makefile_pl => 'traditional', meta_add => { resources => { Repository => "http://svn.berlios.de/svnroot/repos/web-cpan/XML-SemanticDiff/", }, }, ); $builder->create_build_script(); README000444000765000765 177711233530415 15516 0ustar00shlomishlomi000000000000XML-SemanticDiff-1.0000XML-SemanticDiff Semantically compare two XML files for equivalence. This is done while ignoring whitespace variations in the text as well as several permutations in the order of the tags. INSTALLATION To install this module, run the following commands: perl Makefile.PL make make test make install SUPPORT AND DOCUMENTATION After installing, you can find documentation for this module with the perldoc command. perldoc XML::SemanticDiff You can also look for information at: Search CPAN http://search.cpan.org/dist/XML-SemanticDiff CPAN Request Tracker: http://rt.cpan.org/NoAuth/Bugs.html?Dist=XML-SemanticDiff AnnoCPAN, annotated CPAN documentation: http://annocpan.org/dist/XML-SemanticDiff CPAN Ratings: http://cpanratings.perl.org/d/XML-SemanticDiff COPYRIGHT AND LICENCE 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. t000755000765000765 011233530415 14730 5ustar00shlomishlomi000000000000XML-SemanticDiff-1.000006pass_to_handler.t000444000765000765 324411233530415 20570 0ustar00shlomishlomi000000000000XML-SemanticDiff-1.0000/tuse Test; BEGIN { plan tests => 1 } use XML::SemanticDiff; $xml1 = <<'EOX'; Some Text EOX $xml2 = <<'EOX'; Rogue EOX my $handler = BetterDiff->new(); my $diff = XML::SemanticDiff->new(diffhandler => $handler); my @results = $diff->compare($xml1, $xml2); ok(@results == 6); package BetterDiff; use strict; sub new { my ($proto, %args) = @_; my $class = ref($proto) || $proto; my $self = \%args; bless ($self, $class); return $self; } sub rogue_element { my $self = shift; my ($element_path, $new_element) = @_; return 1 if $element_path and $new_element; } sub rogue_attribute { my $self = shift; my ($attr, $element_path, $new_element, $old_element) = @_; return 1 if $attr and $element_path and $new_element and $old_element; } sub missing_element { my $self = shift; my ($element_path, $old_element) = @_; return 1 if $element_path and $old_element; } sub missing_attribute { my $self = shift; my ($attr, $element_path, $new_element, $old_element) = @_; return 1 if $attr and $element_path and $new_element and $old_element; } sub attribute_value { my $self = shift; my ($attr, $element_path, $new_element, $old_element) = @_; return 1 if $attr and $element_path and $new_element and $old_element; } sub element_value { my $self = shift; my ($element_path, $new_element, $old_element) = @_; return 1 if $element_path and $new_element and $old_element; } sub namespace_uri { return 1; } 1; 04namespaces.t000444000765000765 153311233530415 17537 0ustar00shlomishlomi000000000000XML-SemanticDiff-1.0000/tuse Test; BEGIN { plan tests => 4 } use XML::SemanticDiff; my $xml1 = <<'EOX'; Some Text EOX my $xml2 = <<'EOX'; Some Text EOX my $xml3 = <<'EOX'; Some Text EOX my $diff = XML::SemanticDiff->new(); my @results = $diff->compare($xml1, $xml2); ok(@results == 0); @results = $diff->compare($xml1, $xml3); ok(@results == 1); ok($results[0]->{context} eq '/root[1]/el1[1]'); ok($results[0]->{message} =~ /namespace/gi); 05simple_handler.t000444000765000765 173711233530415 20415 0ustar00shlomishlomi000000000000XML-SemanticDiff-1.0000/tuse Test; BEGIN { plan tests => 1 } use XML::SemanticDiff; $xml1 = <<'EOX'; Some Text EOX $xml2 = <<'EOX'; Rogue EOX my $handler = SimpleDiff->new(); my $diff = XML::SemanticDiff->new(diffhandler => $handler); my @results = $diff->compare($xml1, $xml2); ok(@results == 8); package SimpleDiff; use strict; sub new { my ($proto, %args) = @_; my $class = ref($proto) || $proto; my $self = \%args; bless ($self, $class); return $self; } sub init { return 1; } sub rogue_element { return 1; } sub rogue_attribute { return 1; } sub missing_element { return 1; } sub missing_attribute { return 1; } sub attribute_value { return 1; } sub element_value { return 1; } sub namespace_uri { return 1; } sub final { # return 1; } 1; 02load_xml.t000444000765000765 36211233530415 17174 0ustar00shlomishlomi000000000000XML-SemanticDiff-1.0000/tuse Test; BEGIN { plan tests => 1 } use XML::SemanticDiff; my $diff = XML::SemanticDiff->new(); my $xml1 = qq* Some Text *; my $foo = $diff->read_xml($xml1); ok($foo); 14ignore_xpath.t000444000765000765 127611233530415 20114 0ustar00shlomishlomi000000000000XML-SemanticDiff-1.0000/tuse strict; use warnings; use Test::More tests => 2; use XML::SemanticDiff; my $xml1 = <<'EOX'; Some Text EOX my $xml2 = <<'EOX'; Some Text EOX #TEST { my $diff_simple = XML::SemanticDiff->new(); my @results = $diff_simple->compare($xml1, $xml2); ok(@results, "XMLs are not identical"); } #TEST { my $diff_ignore = XML::SemanticDiff->new(ignorexpath=>["/root/el3"]); my @results = $diff_ignore->compare($xml1, $xml2); ok((!@results), "XMLs should count identical if xpath /root/el3 is excluded"); } 13to-doc-read.t000444000765000765 57311233530415 17501 0ustar00shlomishlomi000000000000XML-SemanticDiff-1.0000/tuse strict; use warnings; use Test::More tests => 1; use XML::SemanticDiff; my $xml_text = <<'EOF'; Hello There! EOF my $diff = XML::SemanticDiff->new(); my $to_processed_xml = $diff->read_xml($xml_text); my @results = $diff->compare($xml_text, $to_processed_xml); # TEST is_deeply(\@results, [], "Accepted the processed XML in the second argument"); 15ignore_multi.t000444000765000765 167411233530415 20125 0ustar00shlomishlomi000000000000XML-SemanticDiff-1.0000/tuse strict; use warnings; use Test::More tests => 3; use XML::SemanticDiff; my $xml1 = <<'EOX'; Some Text EOX my $xml2 = <<'EOX'; Some Text EOX #TEST { my $diff_simple = XML::SemanticDiff->new(); my $results = $diff_simple->compare($xml1, $xml2); ok($results == 2, "Two differences in XMLs"); } #TEST { my $diff_ignore = XML::SemanticDiff->new(ignorexpath=>["/root/el3"]); my $results = $diff_ignore->compare($xml1, $xml2); ok($results == 1, "Only one difference if /root/el3 is excluded"); } #TEST { my $diff_multiignore = XML::SemanticDiff->new(ignorexpath=>["/root/el3", "/root/el4"]); my $results = $diff_multiignore->compare($xml1, $xml2); ok($results == 0, "XMLs should count identical if xpaths /root/el3 and /root/el4 are excluded"); } 10wide-chars.t000444000765000765 57711233530415 17432 0ustar00shlomishlomi000000000000XML-SemanticDiff-1.0000/tuse strict; use warnings; use Test::More tests => 2; use XML::SemanticDiff; my $diff = XML::SemanticDiff->new(); my $xml_text = <<"EOX"; \x{263A} EOX my @results = eval { $diff->compare($xml_text, $xml_text) }; # TEST is ($@, q{}, "No exceptions were thrown"); # TEST ok ((!@results), q{$xml_text is identical to itself}); 09two-tags.t000444000765000765 72611233530415 17155 0ustar00shlomishlomi000000000000XML-SemanticDiff-1.0000/tuse strict; use warnings; use Test::More tests => 1; use XML::SemanticDiff; my $first_item_is_t = <<"EOF";

T

G

EOF my $first_item_is_f = <<"EOF";

F

G

EOF my $diff = XML::SemanticDiff->new(); my @results = $diff->compare($first_item_is_t, $first_item_is_f); # TEST is (scalar(@results), 1, "Making sure there's one difference in the XML"); 1; 01basic.t000444000765000765 23511233530415 16454 0ustar00shlomishlomi000000000000XML-SemanticDiff-1.0000/tuse Test; BEGIN { plan tests => 2 } END { ok(0) unless $loaded } use XML::SemanticDiff; $loaded = 1; ok(1); my $diff = XML::SemanticDiff->new(); ok($diff); 11tag-in-different-locations.t000444000765000765 252511233530415 22534 0ustar00shlomishlomi000000000000XML-SemanticDiff-1.0000/tuse strict; use warnings; use Test::More tests => 1; use XML::SemanticDiff; my $orig = <<'EOF'; This presentation is a brief overview of the MediaLandscape Product and Serivce Offerings. 19 Central Time (GMT-06:00) Central Time (US & Canada) CST EOF my $derived = <<'EOF'; (GMT-06:00) Central Time (US & Canada) CST 19 Central Time This presentation is a brief overview of the MediaLandscape Product and Serivce Offerings. EOF my $diff = XML::SemanticDiff->new(); my @results = $diff->compare($orig, $derived); # TEST is_deeply ( \@results, [], "Making sure two XMLs with variation of tag locations are considered identical - per bug #18491" ); pod-coverage.t000444000765000765 25411233530415 17606 0ustar00shlomishlomi000000000000XML-SemanticDiff-1.0000/t#!perl -T use Test::More; eval "use Test::Pod::Coverage 1.04"; plan skip_all => "Test::Pod::Coverage 1.04 required for testing POD coverage" if $@; all_pod_coverage_ok(); pod.t000444000765000765 21411233530415 16011 0ustar00shlomishlomi000000000000XML-SemanticDiff-1.0000/t#!perl -T use Test::More; eval "use Test::Pod 1.14"; plan skip_all => "Test::Pod 1.14 required for testing POD" if $@; all_pod_files_ok(); 03simple_compare.t000444000765000765 117011233530415 20413 0ustar00shlomishlomi000000000000XML-SemanticDiff-1.0000/tuse strict; use warnings; use Test::More tests => 2; use XML::SemanticDiff; my $xml1 = <<'EOX'; Some Text EOX my $xml2 = <<'EOX'; Rogue EOX my $diff = XML::SemanticDiff->new(); my @results = $diff->compare($xml1, $xml2); # TEST is (scalar(@results), 6, "Number of results in comparing two different XML texts" ); @results = $diff->compare($xml1, $xml1); # TEST ok ((!@results), "Identical XMLs generate identical results"); 08nonexist_ns.t000444000765000765 472111233530415 17775 0ustar00shlomishlomi000000000000XML-SemanticDiff-1.0000/t#!/usr/bin/perl -w use strict; use warnings; use Test::More tests => 2; use XML::SemanticDiff; $SIG{__WARN__} = sub { die $_[0]; }; my $xml1 = <<'EOX'; Create a Great Personal Home Site

Books

These are my books.

Fiction books

Little Women by Louisa May Alcott.

Computer books

EOX my $xml2 = <<'EOX'; Create a Great Personal Home Site

Books

These are my books.

Fiction books

Little Women by Louisa May Alcott.

Computer books

EOX my $diff = XML::SemanticDiff->new(); my @results=(qw(Humpty Dumpty sat on a wall)); eval { @results = $diff->compare($xml1, $xml2); }; # TEST is ($@, "", "No exception was thrown"); # TEST ok ((@results == 0), "XML is OK."); 12missing-element-has-o-as-cdata.t000444000765000765 206411233530415 23177 0ustar00shlomishlomi000000000000XML-SemanticDiff-1.0000/t# This is a regression test file for bug: # # http://rt.cpan.org/Ticket/Display.html?id=2322 # # It seems to already have been fixed by the time this test was written. use strict; use warnings; use Test::More tests => 1; use XML::SemanticDiff; package MyDiffHandler; sub new { my $class = shift; my $self = {}; bless $self, $class; $self->{save_CData} = []; return $self; } sub missing_element { my $self = shift; my ($elem, $properties) = @_; push @{$self->{save_CData}}, { cdata => $properties->{CData} }; return {}; } package main; my $handler = MyDiffHandler->new(); my $diff = XML::SemanticDiff->new(diffhandler => $handler); my $xml_with_empty_element = <<'EOF'; Quark EOF my $xml_without_empty_element = <<'EOF'; Quark EOF my @results = $diff->compare( $xml_with_empty_element, $xml_without_empty_element, ); # TEST is_deeply ($handler->{save_CData}, [ { cdata => undef } ], "Testing that the cdata for an empty element is the empty string." ); 07pitest.t000444000765000765 160511233530415 16733 0ustar00shlomishlomi000000000000XML-SemanticDiff-1.0000/tuse Test; BEGIN { plan tests => 3 } use XML::SemanticDiff; $xml1 = <<'EOX'; EOX $xml2 = <<'EOX'; EOX $xml3 = <<'EOX'; EOX my $diff = XML::SemanticDiff->new(); my @results = $diff->compare($xml1, $xml2); ok(@results == 2); @results = $diff->compare($xml1, $xml1); ok(@results == 0); my $full = XML::SemanticDiff->new(keepdata => 1, keeplinenums => 1); @results = $full->compare($xml1, $xml3); #foreach my $msg (@results) { # warn "RES " . $msg->{startline} . "\n"; #} ok(@results == 1); eg000755000765000765 011233530415 15060 5ustar00shlomishlomi000000000000XML-SemanticDiff-1.0000camelids.xml000444000765000765 5220311233530415 17542 0ustar00shlomishlomi000000000000XML-SemanticDiff-1.0000/eg Bactrian Camel 450 to 500 kg. The most noticeable feature of C. bactrianus is its two humps. At the hump, its average height is 213 cm (7 feet). A thick, shaggy, dark brown to beige coat covers the camel during cold weather and is shed when the temperature rises. Longer hair hangs from the neck and gives the appearance of a beard. Bushy eyebrows, a double row of eyelashes, ears lined with hair and the ability to close nostrils and lips tightly serve as protection from harsh conditions. Their tough, even-toed feet help them to cross the rocky desert in Asia and travel well through snow or sand. Camels are herbivores. Their preferred plants are dry, prickly, salty, and/or bitter. When other nutrient sources are not available, the camel may feed on bones, other animals' skin, or different kinds of flesh. In more extreme conditions, they may eat rope, sandals, and even tents. The camel's ability to feed on a wide range of foods allows it to live in areas with sparse vegetation. With tough mouths that can withstand sharp objects such as thorns, the digestion process begins. The first time food is swallowed it is not fully chewed. The partly masticated food (called cud) goes into the stomach and later is brought back up for further chewing. Camels can go for several days without water. When water is available, they drink only to replace what is missing from their body. This amount can vary from nothing to 114 liters. Drinking the whole 114 liters of water takes only ten minutes. The camel also has the ability to quench its thirst with salty or brackish water. In the winter months, plants alone provide water. A common misconception is that the camel's humps are for water storage. In reality, the humps contain a large amount of fat and are use for nourishment when food is scarce. This feature gives the camel the capability to go many days without eating. Each hump can hold up to 36 kg of fat. The hump decreases in size and become flabby as its contents are metabolized. Depletion of the hump is directly linked to the time between eating and the amount of energy expended. Thus, the size of the hump serves as an indication of C. bactrian's health, food supply and general well-being. The stomach is the camel's water storage space. In it, water is retained in several sac-shaped containers. Approximately one and a half gallons of water can be held in the stomach. Mating season occurs in the fall, with inbreeding often involved in domesticated camels. The males during this time are often violent and may bite, spit, or attempt to sit on other male camels. The age of sexual maturity varies, but is usually reached at three to five years. Gestation lasts thirteen months. One or occasionally two calves are produced. The female can give birth to a new calf every other year. The baby calf is precocial, having the ability to stand at birth and walk only a few hours after. The young calf stays with its mother for three to five years, until it reaches sexual maturity. Domestic camels travel in caravans across the desert. An adult male acts as leader for a small group that may consist of six to twenty others. Constantspeed must be maintained at all times while moving. To help ensure this tempo the camels move by pacing. Pacing consists of two legs on the same sideof the body moving at once, creating a rolling motion. This shifts the weight from side to side; a passenger may find this movement very uncomfortable. Camels also have the capability to run and can do so at ten to twenty miles per hour. The camel's habitat consists mainly of Asia's deserts. The temperature ranges from -29 degrees Celsius in the winter to 38 degrees Celsius in the summer. Camels were thought to be extinct in the wild until an expedition found some wild C. bactrianus in the Gobi desert in 1957. These wild groups are in the severedanger of going extinct and little is known about them. The estimated number of wild camels ranges from 500 to 1000. Dromedary, or Arabian Camel 300 to 690 kg. The dromedary camel is characterized by a long-curved neck, deep-narrow chest, and a single hump. The hump is composed of fat bound together by fibrous tissue, acting as food storage in times of need. The size of the hump varies with the nutritional status of the camel, becoming smaller to non-existent during times of starvation. The lips of the dromedary camel are thickened to allow consumption of course, thorny plants. Dromedaries are typically caramel brown or sandy brown in color, however, shades can range from almost black to nearly white. Hair length is longer on the throat, shoulder, and hump areas. The feet of dromedaries are pad-shaped and adapted for traveling on sand. They can be easily injured on sharp stones and are unsuitable for slippery or muddy conditions. Male dromedaries, in comparison to females, are about 10% heavier, weighing 400-600 kg, and are about 10 cm taller at shoulder height, measuring 1.8-2.0 m. Additionally, male dromedaries have an inflatable soft palate which is used to attract females. Dromedary camels have a total of 34 teeth, with a dental formula of 1/3; 1/1; 3/2; 3/3. The dromedary camel is a herbivore. The camel eats primarily thorny plants, dry grasses and saltbush; however, it will eat most anything that grows in the desert (Oakland Zoo 1993). Dromedaries primarily browse, with shrubs and forbs composing up to 70% of their diet. About 8-12 hours/day is spent grazing with equal amounts spent ruminating (Kohler-Rollefson 1991). When foraging, camels tend to spread over large areas and select only a few leaves from each plant. This type of feeding behavior reduces the stress on the plant communities and eases competition with other arid region herbivores (Busch Gardens 1996). Additionally, dromedaries need 6 to 8 times as much salt as other animals for adsorption and storage of water. Consequently, 1/3 of their food intake must be halophytes. Dromedaries browse up to a height of 3.5 m, breaking off branches or stripping off the leaves in one movement. While browsing, they use their lips to grasp the food, then chew each bite 40-50 times. The mouth is kept open while chewing thorny food (Kohler-Rollefson 1991) The dromedary camel has a lifespan of about 40-50 years (Busch Gardens 1996). Females reach sexual maturity around age 3 and mate around age 4 or 5. Males begin to rut by age 3, but do not reach full sexual maturity until age 6. Typically, males and females are seasonal breeders. Breeding occurs in winter and overlaps with the rainy season; both vary in respect to the camel's geographic range. The onset of the breeding season is believed to be cued by nutritional status of the camel and the daylength. During competition for females, the males threaten each other by making low noises with the fleshy fold of their mouths, stand as tall as possible, and repeat a series of head movements including lowering, lifting, and bending their necks backwards. Upon confrontation, fighting males attempt to bring their opponent to the ground by biting at his legs and taking the opponent's head in between his jaws. Copulation time ranges from 7-35 minutes, averaging 11-15 minutes. The gestation period typically lasts for a period of 15 months, followed by the birth of a single calf. The calf can move freely by the end of the first day. Maternal care generally lasts for 1 to 2 years. Calves typically experience a growth rate of .19-.31 kg/day for the first year. (Gauthier-Pilthers and Dagg 1981, Kohler-Rollefson 1991) With the exception of rutting males, dromedaries show very little aggressive behavior. Confrontations among dromedaries include pushing each other with their whole body or lowered head and neck; snapping at each other without biting; and occasionally vomiting cud when they are hurt or excited. Dromedaries usually form groups of 2-20 individuals. The basic social unit is the family, consisting of one male, and one to several females, subadults, and young. The male within the family unit prevents contact between female camels within the family and stray males by either standing or walking in between them, or by driving the stray males away. The male is the dominant member of the family group and directs the family from the rear while the females take turns leading. Dromedaries tend to travel by walking single file. Dromedary camels find comfort in scratching parts of their body with their front or hind legs, or with their lower incisors. They are also often observed rubbing against trees. Additionally, they seem to like to roll in sand (Gauthier-Pilthers and Dagg 1981, Kohler-Rollefson 1991). The camels prefer desert conditions characterized by a long dry season and a short rainy season. Introduction of the dromedary into other climates has proven unsuccessful as the camel is sensitive to the cold and humidity (Nowak 1991). Since the dromedary camel is domesticated, the camel has no special status in conservation (Busch Gardens 1996). Llama 130 to 155 kg. Llamas feet are slender and their limbs are long. They have long, dense fine wool on their bodies. The hair on their head, neck, and limbs is shorter than on their torso. Llamas have remarkable variety in their body sizes and shapes. The larger animals are more prevelant because of their use as "beasts of burden." Body length ranges from 153-200 cm, shoulder height from 100-125 cm, and tail length from 22-25 cm. The coloring of their fur is also variable, ranging from all white, to brown, yellow, blue and black, and sometimes with checks and spots. Llamas are herbivorous, feeding on many kinds of grasses and leaves. Llamas reach sexual maturity at about 12-24 months. Females give birth every other year. Mating occurs in August and September. The gestation period is 348-368 days. Llamas produce one offspring at a time (rarely two). The weight at birth is 8-16 kg. Weaning occurs at 5-8 months. The Lama glama lives only in domestication. They are mostly kept grazing freely on grasslands and scrublands at elevations between 7,400-12,800 ft. (2,300-4,000 m). Llamas are very graceful in their movements. They run with a swinging stride, with their front and hind legs moving in unison on each side. Llamas lie down to rest and sleep. They are adept at spitting regurgitated food. Llamas use certain excretion sites that form dung heaps up to 2.4 meters in diameter. Fighting between males involves leg biting and "neck dominance." Copulation occurs while animals are in a prone position. Llamas are found in deserts, mountainous areas, and grasslands. The population of llamas has declined since road building reduced their importance in transportation. Guanaco 115 to 140 kg. They stand at 1,100 to 1,200mm at the shoulder and have slender bodies with long limbs and neck. The head is typical of camelids with long, pointed ears and cleft, highly mobile lips. Their fur can be long, thick and wooly, especially along the flanks, chest and thighs. It is reddish-brown dorsally, and the underparts are white. Guanacos are herbivores that can inhabit dry areas and forego drinking for long periods. They are versatile foragers, both browsing and grazing on grasses and plants. Females are apparently induced ovulators, and especially in the southern end of the range breeding reaches a peak in February. Young are born in December to February after an eleven month gestation period. They weigh 8-15kg at birth and nurse for eleven to fifteen months. Usually females do not breed until there third year. There are three types of social groups: family groups, male troops, and solitary males. A family band is composed of a single breeding male, several females, and offspring. Males limit the size of their group by driving out young males of six to twelve months and driving off males and sometimes females trying to enter the group. Males defend a territory that the group resides on, and the territory is demarcated by large communal defecation piles. Only about 18% of males are in a family group; the others are in bands or solitary. The all-male bands are generally made up of young males. Males in these herds learn fighting ability through play fights. The solitary males tend to be mature males looking for females or herds to take over. Guanacos inhabit grasslands and shrublands from sea level to 4,000m. Occasionally they winter in forests. Guanacos have had their numbers drastically reduced due to human pressures of habitat encroachment, habitat destruction, and hunting. In addition, climatic changes are also blamed for decreases in population size and range. Vicuna 35 to 65 kg. The vicuna is the smallest living species among the family Camelidae. Head and body length is 1,250-1,900 mm, tail length is 150-250mm, and shoulder height is 700-1,100mm. A slender body and relatively long neck and limbs give a vicuna an elegant appearance. The ears are long, pointed, and narrow. The head is round and yellowish to red-brown in color. The long neck has yellowish red bib. The underside and inner parts of the flanks are dirty white. A strange mane, 20-30cm long, with silky-white hair adorns the chest. Overall, the pelage is uniform and soft. Compared to the similar-looking Lama guanicoe, the vicuna is one fourth the size, its body is paler, and it lacks callosities on the inner sides of the forelimbs. Relative weight of the brain is greater than that of the guanaco. Among living artiodactyls, vicunas have unique, rodent-like incisors that are covered with enamel on only one side. Features believed to be adaptations to high altitudes include a large heart, specialized blood cells with hemoglobin of greater affinty for oxygen, and a weight that is 50 percent heavier than other mammals of the same size. Vision and hearing is good, although the former is far more developed. Olfaction is fairly poor. Nowak (1991), Grizmek (1990). The vicuna is strictly a grazer. Its diet consist of mostly short perennial grasses. The incisors are specially adapted to its diet. They are large and continuously growing as in rodents. The young often graze while lying down. Both young and adults chew cud when they are at rest. Unlike most other camelids, the vicuna requires daily intake of water. Therefore, when selecting a territory, it searches an area with favorable watering sites. The average feeding range is 184ha. Nowak (1991), Grizmek (1990), MacDonald (1984). Mating begins in March and April. They mate while lying down on their chests, and copulation lasts 10-20 minutes. After 330-350 days of gestation period, a female gives birth to a single offspring of 4-6 kg in February and March. The female gives birth in a standing position, and it neither licks nor eats the afterbirth. The mother mates soon after giving birth. The young is mobile after just 15 minutes at birth. It remains close aside its mother for at least 8 months. It continues to suckle until it reaches 10 months. Young females at this stage are expelled from the herd by the dominant male. For young males, this happens at 4-9 months. Expelled females are usually accepted into another group. Females are capable of mating when they reach 2 years. Some are still reproductively active at 19 years. Vicunas in the wild live up to 15-20 years. In captivity, an individual was reported to have lived 24 years. MacDonald (1984), Nowak (1991), Grizmek (1990). Vicunas are alert and shy animals that flee very rapidly. They are capable of running 47 km/hr at an elevation of 4,500 meters. Movement is extremely graceful compared to any other hoofed animal. When in danger, vicunas make a clear, whistling sound. The dominant male warns its herd with an alarm call, and positions itself between the threat and the members. A single dominant male leads a group of females and juveniles. It determines the range of the territory and group membership, and it drives other males away from the family. The territorial male keeps its members closely together at a distance of no more than 160ft. Group members display submission to the male by laying their neck over the back. Family groups are closed societies, excluding alien males and, at times, preventing even young females from joining. The average size of a family is 6-10 individuals depending on the feeding condition in the territory. Vicunas are one of the few ungulates to possess a feeding territory and a separate sleeping territory. They are diurnal, and at night they retreat to their sleeping areas at higher altitudes. Adult males that do not lead any herd become either solitary, or they form a large group of 30 or even 150 individuals. However, there is low cohesiveness among the members of these bachelor herds, and hierarchy is absent. Nowak (1991), Grizmek (1990). Vicunas are found in semiarid rolling grasslands and plains at altitudes of 3,500-5,750 meters. These lands are covered with short and tough vegetation. Due to their daily water demands, vicunas live in areas where water is readily accessible. Climate in the habitat is usually dry and cold. Nowak (1991), Grizmek (1990). The vicuna is classified as vulnerable by the IUCN, and as endangered by the USDI. During the period of the Incas, the total population reached 1.5 million. With the fall of the empire, the number dropped dramatically due to massive slaughter by the conquerors and the settlers. By 1960, the number decreased to only 6,000. Recent efforts of establishing national parks and organizations for protection of vicunas have brought the population back up to 125,000. About half of this number live at the Pampas Galeras National Vicuna Reserve in Peru. Nowak (1991), Grzimek (1990). camelids2.xml000444000765000765 4501211233530415 17624 0ustar00shlomishlomi000000000000XML-SemanticDiff-1.0000/eg Bactrian Camel The most feature of C. bactrianus is its two humps. At the hump, its average height is 213 cm (7 feet). A thick, shaggy, dark brown to beige coat covers the camel during cold weather and is shed when the temperature rises. Longer hair hangs from the neck and gives the appearance of a beard. Bushy eyebrows, a double row of eyelashes, ears lined with hair and the ability to close nostrils and lips tightly serve as protection from harsh conditions. Their tough, even-toed feet help them to cross the rocky desert in Asia and travel well through snow or sand. up to 36 kg of fat. The hump decreases in size and become flabby as its contents are metabolized. Depletion of the hump is directly linked to the time between eating and the amount of energy expended. Thus, the size of the hump serves as an indication of C. bactrian's health, food supply and general well-being. The stomach is the camel's water storage space. In it, water is retained in several sac-shaped containers. Approximately one and a half gallons of water can be held in the stomach. it reaches sexual maturity. The camel's habitat consists mainly of Asia's deserts. The temperature ranges from -29 degrees Celsius in the winter to 38 degrees Celsius in the summer. Camels were thought to be extinct in the wild until an expedition found some wild C. bactrianus in the Gobi desert in 1957. These wild groups are in the severedanger of going extinct and little is known about them. The estimated number of wild camels ranges from 500 to 1000. Dromedary, or Arabian Camel 300 to 690 kg. The dromedary camel is characterized by a long-curved neck, deep-narrow chest, and a single hump. The hump is composed of fat bound together by fibrous tissue, acting as food storage in times of need. The size of the hump varies with the nutritional status of the camel, becoming smaller to non-existent during times of starvation. The lips of the dromedary camel are thickened to allow consumption of course, thorny plants. Dromedaries are typically caramel brown or sandy brown in color, however, shades can range from almost black to nearly white. Hair length is longer on the throat, shoulder, and hump areas. The feet of dromedaries are pad-shaped and adapted for traveling on sand. They can be easily injured on sharp stones and are unsuitable for slippery or muddy conditions. Male dromedaries, in comparison to females, are about 10% heavier, weighing 400-600 kg, and are about 10 cm taller at shoulder height, measuring 1.8-2.0 m. Additionally, male dromedaries have an inflatable soft palate which is used to attract females. Dromedary camels have a total of 34 teeth, with a dental formula of 1/3; 1/1; 3/2; 3/3. The dromedary camel is a herbivore. The camel eats primarily thorny plants, dry grasses and saltbush; however, it will eat most anything that grows in the desert (Oakland Zoo 1993). Dromedaries primarily browse, with shrubs and forbs composing up to 70% of their diet. About 8-12 hours/day is spent grazing with equal amounts spent ruminating (Kohler-Rollefson 1991). When foraging, camels tend to spread over large areas and select only a few leaves from each plant. This type of feeding behavior reduces the stress on the plant communities and eases competition with other arid region herbivores (Busch Gardens 1996). Additionally, dromedaries need 6 to 8 times as much salt as other animals for adsorption and storage of water. Consequently, 1/3 of their food intake must be halophytes. Dromedaries browse up to a height of 3.5 m, breaking off branches or stripping off the leaves in one movement. While browsing, they use their lips to grasp the food, then chew each bite 40-50 times. The mouth is kept open while chewing thorny food (Kohler-Rollefson 1991) The dromedary camel has a lifespan of about 40-50 years (Busch Gardens 1996). Females reach sexual maturity around age 3 and mate around age 4 or 5. Males begin to rut by age 3, but do not reach full sexual maturity until age 6. Typically, males and females are seasonal breeders. Breeding occurs in winter and overlaps with the rainy season; both vary in respect to the camel's geographic range. The onset of the breeding season is believed to be cued by nutritional status of the camel and the daylength. During competition for females, the males threaten each other by making low noises with the fleshy fold of their mouths, stand as tall as possible, and repeat a series of head movements including lowering, lifting, and bending their necks backwards. Upon confrontation, fighting males attempt to bring their opponent to the ground by biting at his legs and taking the opponent's head in between his jaws. Copulation time ranges from 7-35 minutes, averaging 11-15 minutes. The gestation period typically lasts for a period of 15 months, followed by the birth of a single calf. The calf can move freely by the end of the first day. Maternal care generally lasts for 1 to 2 years. Calves typically experience a growth rate of .19-.31 kg/day for the first year. (Gauthier-Pilthers and Dagg 1981, Kohler-Rollefson 1991) With the exception of rutting males, dromedaries show very little aggressive behavior. Confrontations among dromedaries include pushing each other with their whole body or lowered head and neck; snapping at each other without biting; and occasionally vomiting cud when they are hurt or excited. Dromedaries usually form groups of 2-20 individuals. The basic social unit is the family, consisting of one male, and one to several females, subadults, and young. The male within the family unit prevents contact between female camels within the family and stray males by either standing or walking in between them, or by driving the stray males away. The male is the dominant member of the family group and directs the family from the rear while the females take turns leading. Dromedaries tend to travel by walking single file. Dromedary camels find comfort in scratching parts of their body with their front or hind legs, or with their lower incisors. They are also often observed rubbing against trees. Additionally, they seem to like to roll in sand (Gauthier-Pilthers and Dagg 1981, Kohler-Rollefson 1991). The camels prefer desert conditions characterized by a long dry season and a short rainy season. Introduction of the dromedary into other climates has proven unsuccessful as the camel is sensitive to the cold and humidity (Nowak 1991). Since the dromedary camel is domesticated, the camel has no special status in conservation (Busch Gardens 1996). Llama 130 to 155 kg. Llamas feet are slender and their limbs are long. They have long, dense fine wool on their bodies. The hair on their head, neck, and limbs is shorter than on their torso. Llamas have remarkable variety in their body sizes and shapes. The larger animals are more prevelant because of their use as "beasts of burden." Body length ranges from 153-200 cm, shoulder height from 100-125 cm, and tail length from 22-25 cm. The coloring of their fur is also variable, ranging from all white, to brown, yellow, blue and black, and sometimes with checks and spots. Llamas are herbivorous, feeding on many kinds of grasses and leaves. Llamas reach sexual maturity at about 12-24 months. Females give birth every other year. Mating occurs in August and September. The gestation period is 348-368 days. Llamas produce one offspring at a time (rarely two). The weight at birth is 8-16 kg. Weaning occurs at 5-8 months. The Lama glama lives only in domestication. They are mostly kept grazing freely on grasslands and scrublands at elevations between 7,400-12,800 ft. (2,300-4,000 m). Llamas are very graceful in their movements. They run with a swinging stride, with their front and hind legs moving in unison on each side. Llamas lie down to rest and sleep. They are adept at spitting regurgitated food. Llamas use certain excretion sites that form dung heaps up to 2.4 meters in diameter. Fighting between males involves leg biting and "neck dominance." Copulation occurs while animals are in a prone position. Llamas are found in deserts, mountainous areas, and grasslands. The population of llamas has declined since road building reduced their importance in transportation. Guanaco 115 to 140 kg. They stand at 1,100 to 1,200mm at the shoulder and have slender bodies with long limbs and neck. The head is typical of camelids with long, pointed ears and cleft, highly mobile lips. Their fur can be long, thick and wooly, especially along the flanks, chest and thighs. It is reddish-brown dorsally, and the underparts are white. Guanacos are herbivores that can inhabit dry areas and forego drinking for long periods. They are versatile foragers, both browsing and grazing on grasses and plants. Females are apparently induced ovulators, and especially in the southern end of the range breeding reaches a peak in February. Young are born in December to February after an eleven month gestation period. They weigh 8-15kg at birth and nurse for eleven to fifteen months. Usually females do not breed until there third year. There are three types of social groups: family groups, male troops, and solitary males. A family band is composed of a single breeding male, several females, and offspring. Males limit the size of their group by driving out young males of six to twelve months and driving off males and sometimes females trying to enter the group. Males defend a territory that the group resides on, and the territory is demarcated by large communal defecation piles. Only about 18% of males are in a family group; the others are in bands or solitary. The all-male bands are generally made up of young males. Males in these herds learn fighting ability through play fights. The solitary males tend to be mature males looking for females or herds to take over. Guanacos inhabit grasslands and shrublands from sea level to 4,000m. Occasionally they winter in forests. Guanacos have had their numbers drastically reduced due to human pressures of habitat encroachment, habitat destruction, and hunting. In addition, climatic changes are also blamed for decreases in population size and range. Vicuna 35 to 65 kg. The vicuna is the smallest living species among the family Camelidae. Head and body length is 1,250-1,900 mm, tail length is 150-250mm, and shoulder height is 700-1,100mm. A slender body and relatively long neck and limbs give a vicuna an elegant appearance. The ears are long, pointed, and narrow. The head is round and yellowish to red-brown in color. The long neck has yellowish red bib. The underside and inner parts of the flanks are dirty white. A strange mane, 20-30cm long, with silky-white hair adorns the chest. Overall, the pelage is uniform and soft. Compared to the similar-looking Lama guanicoe, the vicuna is one fourth the size, its body is paler, and it lacks callosities on the inner sides of the forelimbs. Relative weight of the brain is greater than that of the guanaco. Among living artiodactyls, vicunas have unique, rodent-like incisors that are covered with enamel on only one side. Features believed to be adaptations to high altitudes include a large heart, specialized blood cells with hemoglobin of greater affinty for oxygen, and a weight that is 50 percent heavier than other mammals of the same size. Vision and hearing is good, although the former is far more developed. Olfaction is fairly poor. Nowak (1991), Grizmek (1990). The vicuna is strictly a grazer. Its diet consist of mostly short perennial grasses. The incisors are specially adapted to its diet. They are large and continuously growing as in rodents. The young often graze while lying down. Both young and adults chew cud when they are at rest. Unlike most other camelids, the vicuna requires daily intake of water. Therefore, when selecting a territory, it searches an area with favorable watering sites. The average feeding range is 184ha. Nowak (1991), Grizmek (1990), MacDonald (1984). Mating begins in March and April. They mate while lying down on their chests, and copulation lasts 10-20 minutes. After 330-350 days of gestation period, a female gives birth to a single offspring of 4-6 kg in February and March. The female gives birth in a standing position, and it neither licks nor eats the afterbirth. The mother mates soon after giving birth. The young is mobile after just 15 minutes at birth. It remains close aside its mother for at least 8 months. It continues to suckle until it reaches 10 months. Young females at this stage are expelled from the herd by the dominant male. For young males, this happens at 4-9 months. Expelled females are usually accepted into another group. Females are capable of mating when they reach 2 years. Some are still reproductively active at 19 years. Vicunas in the wild live up to 15-20 years. In captivity, an individual was reported to have lived 24 years. MacDonald (1984), Nowak (1991), Grizmek (1990). Vicunas are alert and shy animals that flee very rapidly. They are capable of running 47 km/hr at an elevation of 4,500 meters. Movement is extremely graceful compared to any other hoofed animal. When in danger, vicunas make a clear, whistling sound. The dominant male warns its herd with an alarm call, and positions itself between the threat and the members. A single dominant male leads a group of females and juveniles. It determines the range of the territory and group membership, and it drives other males away from the family. The territorial male keeps its members closely together at a distance of no more than 160ft. Group members display submission to the male by laying their neck over the back. Family groups are closed societies, excluding alien males and, at times, preventing even young females from joining. The average size of a family is 6-10 individuals depending on the feeding condition in the territory. Vicunas are one of the few ungulates to possess a feeding territory and a separate sleeping territory. They are diurnal, and at night they retreat to their sleeping areas at higher altitudes. Adult males that do not lead any herd become either solitary, or they form a large group of 30 or even 150 individuals. However, there is low cohesiveness among the members of these bachelor herds, and hierarchy is absent. Nowak (1991), Grizmek (1990). Vicunas are found in semiarid rolling grasslands and plains at altitudes of 3,500-5,750 meters. These lands are covered with short and tough vegetation. Due to their daily water demands, vicunas live in areas where water is readily accessible. Climate in the habitat is usually dry and cold. Nowak (1991), Grizmek (1990). The vicuna is classified as vulnerable by the IUCN, and as endangered by the USDI. During the period of the Incas, the total population reached 1.5 million. With the fall of the empire, the number dropped dramatically due to massive slaughter by the conquerors and the settlers. By 1960, the number decreased to only 6,000. Recent efforts of establishing national parks and organizations for protection of vicunas have brought the population back up to 125,000. About half of this number live at the Pampas Galeras National Vicuna Reserve in Peru. Nowak (1991), Grzimek (1990). xmlsemdiff000444000765000765 107711233530415 17303 0ustar00shlomishlomi000000000000XML-SemanticDiff-1.0000/eg#!/usr/bin/perl -w ######################################### # xmlsemdiff -- command-line freindly interface to # XML::SemanticDiff # ######################################## use strict; use XML::SemanticDiff; my $diff = XML::SemanticDiff->new(keeplinenums => 1); my ($file1, $file2) = @ARGV; usage() unless defined $file1 and defined $file2; foreach my $change ($diff->compare($file1, $file2)) { print "$change->{message} (between lines $change->{startline} and $change->{endline})\n"; } sub usage { die "usage: $0 one.xml two.xml \n"; } exit; lib000755000765000765 011233530415 15233 5ustar00shlomishlomi000000000000XML-SemanticDiff-1.0000XML000755000765000765 011233530415 15673 5ustar00shlomishlomi000000000000XML-SemanticDiff-1.0000/libSemanticDiff.pm000444000765000765 4502311233530415 20746 0ustar00shlomishlomi000000000000XML-SemanticDiff-1.0000/lib/XMLpackage XML::SemanticDiff; use strict; use warnings; use vars qw/$VERSION/; $VERSION = '1.0000'; use XML::Parser; =head1 NAME XML::SemanticDiff - Perl extension for comparing XML documents. =cut sub new { my ($proto, %args) = @_; my $class = ref($proto) || $proto; my $self = \%args; require XML::SemanticDiff::BasicHandler unless defined $args{diffhandler}; bless ($self, $class); return $self; } sub _is_file { my ($self, $specifier) = @_; return $specifier !~ /\n/g && -f $specifier; } sub _get_pathfinder_obj { my $self = shift; return XML::SemanticDiff::PathFinder::Obj->new(); } sub read_xml { my $self = shift; my ($xml_specifier) = @_; if (ref($xml_specifier) eq 'HASH') { return $xml_specifier; } else { $self->{path_finder_obj} = $self->_get_pathfinder_obj(); my $p = XML::Parser->new( Style => 'Stream', Pkg => 'XML::SemanticDiff::PathFinder', 'Non-Expat-Options' => $self, Namespaces => 1 ); my $ret = $self->_is_file($xml_specifier) ? $p->parsefile($xml_specifier) : $p->parse($xml_specifier) ; $self->{path_finder_obj} = undef; return $ret; } } sub _same_namespace { my ($self, $to, $from) = @_; my $t_e = exists($to->{NamespaceURI}); my $f_e = exists($from->{NamespaceURI}); if (!$t_e && !$f_e) { return 1; } elsif ($t_e && $f_e) { return ($to->{NamespaceURI} eq $from->{NamespaceURI}); } else { return 0; } } sub _match_xpath { my $self = shift; my ($xpath, $flat_name) = @_; my @x_way = split /\//, $xpath; my @f_way = split /\//, $flat_name; for my $i (0..$#x_way) { $x_way[$i]=~s/.*?://g; } for my $i (0..$#f_way) { $f_way[$i]=~s/\[.*?\]$//g; } return 0 if $#x_way > $#f_way; for my $i (0..$#x_way) { if ($x_way[$i] ne $f_way[$i]) { return 0; } } return 1; } # Okay, it's pretty basic... # # We flatten each doc tree to a Perl hash where the keys are "fully qualified" # XPath expressions (/root[1]/element[3]) that represent the unique location # of each XML element, then compare the two hashes. # # Just loop over all the elements of the first hash- if the same key exists # in the second, you compare the text and attributes and delete it. Any # keys not found in the second hash are declared 'missing', and any keys leftover # in the second hash after looping through the elements in the first are 'rogues'. sub compare { my $self = shift; my ($from_xml, $to_xml) = @_; my $from_doc = $self->read_xml($from_xml); my $to_doc = $self->read_xml($to_xml); my @warnings = (); my $handler = $self->{diffhandler} || XML::SemanticDiff::BasicHandler->new(%$self); # drop away nodes matching xpaths to be ignored if (defined $self->{ignorexpath}) { my $ignore = $self->{ignorexpath}; for my $path (@$ignore) { for my $ref ($from_doc, $to_doc) { for my $key (keys %$ref) { if ($self->_match_xpath($path, $key)) { delete $ref->{$key}; } } } } } # fire the init handler push (@warnings, $handler->init($self)) if $handler->can('init'); # loop the elements foreach my $element (sort keys (%$from_doc)) { # element existence check if (defined $to_doc->{$element}) { # element value test unless ($from_doc->{$element}->{TextChecksum} eq $to_doc->{$element}->{TextChecksum}) { push (@warnings, $handler->element_value($element, $to_doc->{$element}, $from_doc->{$element})) if $handler->can('element_value'); } # namespace test unless ($self->_same_namespace($from_doc->{$element},$to_doc->{$element})) { push (@warnings, $handler->namespace_uri($element, $to_doc->{$element}, $from_doc->{$element})) if $handler->can('namespace_uri'); } # attribute tests foreach my $attr (keys(%{$from_doc->{$element}->{Attributes}})) { # attr existence check if (defined ($to_doc->{$element}->{Attributes}->{$attr})) { # attr value test if ($to_doc->{$element}->{Attributes}->{$attr} ne $from_doc->{$element}->{Attributes}->{$attr}){ push (@warnings, $handler->attribute_value($attr, $element, $to_doc->{$element}, $from_doc->{$element})) if $handler->can('attribute_value'); } delete $to_doc->{$element}->{Attributes}->{$attr}; } else { push (@warnings, $handler->missing_attribute($attr, $element, $to_doc->{$element}, $from_doc->{$element})) if $handler->can('missing_attribute'); } } # rogue attrs foreach my $leftover (keys(%{$to_doc->{$element}->{Attributes}})) { push (@warnings, $handler->rogue_attribute($leftover, $element, $to_doc->{$element}, $from_doc->{$element})) if $handler->can('rogue_attribute'); } delete $to_doc->{$element}; } else { push (@warnings, $handler->missing_element($element, $from_doc->{$element})) if $handler->can('missing_element'); } } # rogue elements foreach my $leftover ( keys (%$to_doc) ) { push (@warnings, $handler->rogue_element($leftover, $to_doc->{$leftover})) if $handler->can('rogue_element'); } push (@warnings, $handler->final($self)) if $handler->can('final'); return @warnings; } 1; package XML::SemanticDiff::PathFinder; foreach my $func (qw(StartTag EndTag Text StartDocument EndDocument PI)) { no strict 'refs'; *{__PACKAGE__.'::'.$func} = sub { my $expat = shift; return $expat->{'Non-Expat-Options'}->{path_finder_obj}->$func( $expat, @_ ); }; } package XML::SemanticDiff::PathFinder::Obj; use strict; use Digest::MD5 qw(md5_base64); use Encode qw(encode_utf8); foreach my $accessor (qw(descendents char_accumulator doc opts xml_context PI_position_index)) { no strict 'refs'; *{__PACKAGE__.'::'.$accessor} = sub { my $self = shift; if (@_) { $self->{$accessor} = shift; } return $self->{$accessor}; }; } # PI_position_index is the position index for the PI's below - the processing # instructions. sub new { my $class = shift; my $self = {}; bless $self, $class; $self->_init(@_); return $self; } sub _init { return 0; } sub StartTag { my ($self, $expat, $element) = @_; my %attrs = %_; my @context = $expat->context; my $context_length = scalar (@context); my $parent = $context[$context_length -1]; push (@{$self->descendents()->{$parent}}, $element) if $parent; my $last_ctx_elem = $self->xml_context()->[-1] || { position_index => {}}; push @{$self->xml_context()}, { element => "$element", 'index' => ++$last_ctx_elem->{position_index}->{"$element"}, position_index => {}, }; my $test_context; # if (@context){ # $test_context = '/' . join ('/', map { $_ . '[' . $position_index->{$_} . ']' } @context); # } # $test_context .= '/' . $element . '[' . $position_index->{$element} . ']'; $test_context = $self->_calc_test_context(); $self->doc()->{$test_context} = { NamespaceURI => ($expat->namespace($element) || ""), Attributes => \%attrs, ($self->opts()->{keeplinenums} ? ( TagStart => $expat->current_line) : () ), }; } sub _calc_test_context { my $self = shift; return join("", map { "/". $_->{'element'} . "[" . $_->{'index'} . "]" } @{$self->xml_context()} ); } sub EndTag { my ($self, $expat, $element) = @_; my @context = $expat->context; # if (@context){ # $test_context = '/' . join ('/', map { $_ . '[' . $position_index->{$_} . ']' } @context); #} # $test_context .= '/' . $element . '[' . $position_index->{$element} . ']'; my $test_context = $self->_calc_test_context(); my $text; if ( defined( $self->char_accumulator()->{$element} )) { $text = $self->char_accumulator()->{$element}; delete $self->char_accumulator()->{$element}; } $text ||= 'o'; # warn "text is '$text' \n"; # my $ctx = Digest::MD5->new; # $ctx->add("$text"); # $self->doc()->{"$test_context"}->{TextChecksum} = $ctx->b64digest; $self->doc()->{"$test_context"}->{TextChecksum} = md5_base64(encode_utf8("$text")); if ($self->opts()->{keepdata}) { $self->doc()->{"$test_context"}->{CData} = $text; } if (defined ( $self->descendents()->{$element})) { my $seen = {}; foreach my $child (@{$self->descendents()->{$element}}) { next if $seen->{$child}; $seen->{$child}++; } } $self->doc()->{"$test_context"}->{TagEnd} = $expat->current_line if $self->opts()->{keeplinenums}; pop(@{$self->xml_context()}); } sub Text { my $self = shift; my $expat = shift; my $element = $expat->current_element; my $char = $_; $char =~ s/^\s*//; $char =~ s/\s*$//; $char =~ s/\s+/ /g; $self->char_accumulator()->{$element} .= $char if $char; } sub StartDocument { my $self = shift; my $expat = shift; $self->doc({}); $self->descendents({}); $self->char_accumulator({}); $self->opts($expat->{'Non-Expat-Options'}); $self->xml_context([]); $self->PI_position_index({}); } sub EndDocument { my $self = shift; return $self->doc(); } sub PI { my ($self, $expat, $target, $data) = @_; my $attrs = {}; $self->PI_position_index()->{$target}++; foreach my $pair (split /\s+/, $data) { $attrs->{$1} = $2 if $pair =~ /^(.+?)=["'](.+?)["']$/; } my $slug = '?' . $target . '[' . $self->PI_position_index()->{$target} . ']'; $self->doc()->{$slug} = { Attributes => ($attrs || {}), TextChecksum => "1", NamespaceURI => "", ( $self->opts()->{keeplinenums} ? ( TagStart => $expat->current_line(), TagEnd => $expat->current_line(), ) : () ), }; } 1; =head1 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"; } =head1 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. =head1 METHODS =head2 $obj->new([%options]) Ye olde object constructor. The new() method recognizes the following options: =over 4 =item * 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. =item * 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. =item * 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. =item * ignorexpath This option takes array of strings as argument. 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. =back =head2 @results = $differ->compare($xml1, $xml2) Compares the XMLs $xml1 and $xml2 . $xml1 and $xml2 can be: =over 4 =item * filenames This will be considered if it is a string that does not contain newlines and exists in the filesystem. =item * the XML text itself. This will be considered if it's any kind of string. =item * the results of read_xml(). (see below) This will be considered if it's a hash reference. =back =head2 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. =head1 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. =head1 HANDLER METHODS The following is a list of handler methods that can be used for your custom diff-handler class. =head2 init($self, $diff_obj) The C 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. =head2 rogue_element($self, $element_name, $todoc_element_properties) The C method handles those cases where a given element exists in the to-file but not in the from-file. =head2 missing_element($self, $element_name, $fromdoc_element_properties) The C method handles those cases where a given element exists in the from-file but not in the to-file. =head2 element_value($self, $element, $to_element_properties, $fromdoc_element_properties) The C 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. =head2 namespace_uri($self, $element, $todoc_element_properties, $fromdoc_element_properties) The C 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 and are all considered equivalent as long as they are bound to the same namespace URI. =head2 rogue_attribute($self, $attr_name, $element, $todoc_element_properties) The C method handles those cases where an attribute exists in a given element the to-file but not in the from-file. =head2 missing_attribute($self, $attr_name, $element, $todoc_element_properties, $fromdoc_element_properties) The C method handles those cases where an attribute exists in a given element exists in the from-file but not in the to-file. =head2 attribute_value($self, $attr_name, $element, $todoc_element_properties, $fromdoc_element_properties) The C method handles those cases where the value of an attribute varies between the same element in both documents. =head2 final($self, $diff_obj) The C method is called immediately after the two document HASHes are compared. Like the C 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. =head1 AUTHOR Originally by Kip Hampton, khampton@totalcinema.com . Further Maintained by Shlomi Fish, shlomif@iglu.org.il . =head1 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. =head1 LICENSE This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =head1 SEE ALSO perl(1). =cut SemanticDiff000755000765000765 011233530415 20227 5ustar00shlomishlomi000000000000XML-SemanticDiff-1.0000/lib/XMLBasicHandler.pm000444000765000765 1321211233530415 23260 0ustar00shlomishlomi000000000000XML-SemanticDiff-1.0000/lib/XML/SemanticDiffpackage XML::SemanticDiff::BasicHandler; use strict; use warnings; use vars qw/$VERSION/; $VERSION = '0.94'; sub new { my ($proto, %args) = @_; my $class = ref($proto) || $proto; my $self = \%args; bless ($self, $class); return $self; } sub rogue_element { my $self = shift; my ($element, $properties) = @_; my ($element_name, $parent) = parent_and_name($element); my $info = {context => $parent, message => "Rogue element '$element_name' in element '$parent'."}; if ($self->{keeplinenums}) { $info->{startline} = $properties->{TagStart}; $info->{endline} = $properties->{TagEnd}; } if ($self->{keepdata}) { $info->{new_value} = $properties->{CData}; } return $info; } sub missing_element { my $self = shift; my ($element, $properties) = @_; my ($element_name, $parent) = parent_and_name($element); my $info = {context => $parent, message => "Child element '$element_name' missing from element '$parent'."}; if ($self->{keeplinenums}) { $info->{startline} = $properties->{TagStart}; $info->{endline} = $properties->{TagEnd}; } if ($self->{keepdata}) { $info->{old_value} = $properties->{CData}; } return $info; } sub element_value { my $self = shift; my ($element, $new_properties, $old_properties) = @_; my ($element_name, $parent) = parent_and_name($element); my $info = {context => $element, message => "Character differences in element '$element_name'."}; if ($self->{keeplinenums}) { $info->{startline} = $new_properties->{TagStart}; $info->{endline} = $new_properties->{TagEnd}; } if ($self->{keepdata}) { $info->{old_value} = $old_properties->{CData}; $info->{new_value} = $new_properties->{CData}; } return $info; } sub rogue_attribute { my $self = shift; my ($attr, $element, $properties) = @_; my ($element_name, $parent) = parent_and_name($element); my $info = {context => $element, message => "Rogue attribute '$attr' in element '$element_name'."}; if ($self->{keeplinenums}) { $info->{startline} = $properties->{TagStart}; $info->{endline} = $properties->{TagEnd}; } if ($self->{keepdata}) { $info->{new_value} = $properties->{Attributes}->{$attr}; } return $info; } sub missing_attribute { my $self = shift; my ($attr, $element, $new_properties, $old_properties) = @_; my ($element_name, $parent) = parent_and_name($element); my $info = {context => $element, message => "Attribute '$attr' missing from element '$element_name'."}; if ($self->{keeplinenums}) { $info->{startline} = $new_properties->{TagStart}; $info->{endline} = $new_properties->{TagEnd}; } if ($self->{keepdata}) { $info->{old_value} = $old_properties->{Attributes}->{$attr}; } return $info; } sub attribute_value { my $self = shift; my ($attr, $element, $new_properties, $old_properties) = @_; my ($element_name, $parent) = parent_and_name($element); my $info = {context => $element, message => "Attribute '$attr' has different value in element '$element_name'."}; if ($self->{keeplinenums}) { $info->{startline} = $new_properties->{TagStart}; $info->{endline} = $new_properties->{TagEnd}; } if ($self->{keepdata}) { $info->{old_value} = $old_properties->{Attributes}->{$attr}; $info->{new_value} = $new_properties->{Attributes}->{$attr}; } return $info; } sub namespace_uri { my $self = shift; my ($element, $new_properties, $old_properties) = @_; my ($element_name, $parent) = parent_and_name($element); my $info = {context => $element, message => "Element '$element_name' within different namespace."}; if ($self->{keeplinenums}) { $info->{startline} = $new_properties->{TagStart}; $info->{endline} = $new_properties->{TagEnd}; } if ($self->{keepdata}) { $info->{old_value} = $old_properties->{NamspaceURI}; $info->{new_value} = $new_properties->{NamspaceURI}; } return $info; } sub parent_and_name { my $element = shift; my @steps = split('/', $element); my $element_name = pop (@steps); my $parent = join '/', @steps; $element_name =~ s/\[\d+\]$//; return ($element_name, $parent); } 1; __END__ =head1 NAME XML::SemanticDiff::BasicHandler - Default handler class for XML::SemanticDiff =head1 SYNOPSIS use XML::SemanticDiff; my $diff = XML::SemanticDiff->new(); foreach my $change ($diff->compare($file, $file2)) { print "$change->{message} in context $change->{context}\n"; } =head1 DESCRIPTION This is the default event handler for XML::SemanticDiff. It implements nothing useful apart from the parent class and should never be used directly. Please run perldoc XML::SemanticDiff for more information. =head1 IMPLEMENTED METHODS (FOR INTERNAL USE) =head2 new =head2 rogue_element =head2 missing_element =head2 element_value =head2 rogue_attribute =head2 missing_attribute =head2 attribute_value =head2 namespace_uri =head2 parent_and_name =head1 AUTHOR Kip Hampton khampton@totalcinema.com =head1 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. =head1 SEE ALSO XML::SemanticDiff =cut