Andrew Chilton > XML-Compare-0.04 > XML::Compare

Download:
XML-Compare-0.04.tar.gz

Dependencies

Annotate this POD

CPAN RT

New  1
Open  0
View/Report Bugs
Module Version: 0.04   Source  

NAME ^

XML::Compare - Test if two XML documents semantically the same

SYNOPSIS ^

    use XML::Compare tests => 2;

    my $xml1 = '<foo xmlns="urn:message"><bar baz="buzz">text</bar></foo>';
    my $xml2 = '<f:foo xmlns:f="urn:message"><f:bar baz="buzz">text</f:bar></f:foo>';

    my $same = eval { XML::Compare::same($xml1, $xml2); };
    if ( $same ) {
        print "same\n";
    }
    else {
        print "different: $@\n";
    }

    # OO interface, if you want to customise operation
    my $xml_compare = XML::Compare->new( namespace_strict => 1 );
    if ($xml_compare->is_same($xml1, $xml2)) {
         # same!
    }
    else {
        print "different: " . $xml_compare->error . "\n";
    }

DESCRIPTION ^

This module allows you to test if two XML documents are semantically the same. This also holds true if different prefixes are being used for the xmlns, or if there is a default xmlns in place.

This modules ignores XML Comments.

SUBROUTINES ^

same($xml1, $xml2)

Returns true if the two xml strings are semantically the same.

If they are not the same, it throws an exception with a description in $@ as to why they aren't.

is_same($xml1, $xml2)

Returns true if the two xml strings are semantically the same.

Returns false otherwise. No diagnostic information is available.

is_different($xml1, $xml2)

Returns true if the two xml strings are semantically different. No diagnostic information is available.

Returns false otherwise.

PROPERTIES ^

namespace_strict

(Bool) If this property is set, then all the namespaces of both documents must match exactly. The default, unset, raises an error only if the first document, $xml1, has a namespace defined and this is different from $xml2's (or $xml2 has no namespace).

error

After the 'is_same' method is used, this will contain either the error string from the last comparison error, or undef.

ignore

An array ref of XPath expressions to 'strip' from the documents before comparing. This is implemented by evaluating each XPath expression at the beginning, then removing those nodes from any lists later found.

ignore_xmlns

A hashref of prefix => XMLNS, if you used namespaces on any of the 'ignore' XPath entries.

EXPORTS ^

Nothing.

SEE ALSO ^

XML::LibXML

AUTHOR ^

Andrew Chilton, <andychilton@gmail.com<gt>, <andy@catalyst dot net dot nz<gt>

http://www.chilts.org/blog/

COPYRIGHT & LICENSE ^

This software development is sponsored and directed by New Zealand Registry Services, http://www.nzrs.net.nz/

The work is being carried out by Catalyst IT, http://www.catalyst.net.nz/

Copyright (c) 2009, NZ Registry Services. All Rights Reserved. This software may be used under the terms of the Artistic License 2.0. Note that this license is compatible with both the GNU GPL and Artistic licenses. A copy of this license is supplied with the distribution in the file COPYING.txt.

syntax highlighting: