]> git.sesse.net Git - xml-template/commitdiff
Hack the XML diff script so it can deal with comments in-between. (Is that
authorsgunderson@bigfoot.com <>
Thu, 1 Mar 2007 12:38:17 +0000 (13:38 +0100)
committersgunderson@bigfoot.com <>
Thu, 1 Mar 2007 12:38:17 +0000 (13:38 +0100)
OK, really? It shouldn't matter in practice, only for the tests, so...)
This means perl-sax/include passes.

tests/xml-diff.pl

index eed51b40c153a23a5956a24e4aca0e8fca02d414..b79b252f2264af6c7f3b619be8dc70e7243f2309 100644 (file)
@@ -85,13 +85,35 @@ sub compare {
        my $c1 = $n1->getChildNodes;
        my $c2 = $n2->getChildNodes;
 
-       if ($c1->getLength != $c2->getLength) {
+       my @c1 = ();
+       my @c2 = ();
+
+       # find all elements except comments and blanks (not perfect, since we don't get
+       # compression, but ok)
+       for my $i (0..($c1->getLength-1)) {
+               my $item = $c1->item($i);
+               next if ($item->getNodeType == XML::DOM::COMMENT_NODE);
+               next if ($item->getNodeType == XML::DOM::TEXT_NODE && $item->getData !~ /\S/);
+
+               push @c1, $item;
+       }
+       for my $i (0..($c2->getLength-1)) {
+               my $item = $c2->item($i);
+               next if ($item->getNodeType == XML::DOM::COMMENT_NODE);
+               next if ($item->getNodeType == XML::DOM::TEXT_NODE && $item->getData !~ /\S/);
+
+               push @c2, $item;
+       }
+       
+       if (scalar @c1 != scalar @c2) {
+               print STDERR scalar @c1, "\n";
+               print STDERR scalar @c2, "\n";
                print STDERR "$nsuri1/$lname1 has differing number of children\n";
                exit(1);
        }
 
-       for my $i (0..($c1->getLength-1)) {
-               compare($c1->item($i), $c2->item($i), $nsup1, $nsup2);
+       for my $i (0..$#c1) {
+               compare($c1[$i], $c2[$i], $nsup1, $nsup2);
        }
 
        $nsup1->pop_context;