Rumpa wrote:
> Hi,
>
> I have an XML file which has holds actual result. I have another XML file which has the expected result. I need to compare these two and see if they
> are the same. Whitspaces and placement of the elements might be diferent. What is the best way to handle this?
>
> Example:
> Got this result:
> <store>
> <book>
> <name>XYZ</name>
> <author>ABC</author>
> </book>
> </store>
>
>
> Expected result:
> <store>
> <book>
> <author> ABC </author>
> <name> XYZ </name>
> </book>
> </store>
Use one of the XML parsers found
in the CPAN to transform data into
a suitable structure.
Compare as needed. For example:
use XML::Simple;
use Test::More tests => 1;
use Test:

eep;
my $actual =
'<store>
<book>
<name>XYZ</name>
<author>ABC</author>
</book>
</store>';
my $expected =
'<store>
<book>
<author> ABC </author>
<name> XYZ </name>
</book>
</store>';
my $a_ = XMLin($actual, NormaliseSpace => 2 );
my $e_ = XMLin($expected, NormaliseSpace => 2 );
cmp_deeply(
$a_,
$e_,
"XML::Simple hashes"
);
--
Hope this helps,
Steven