Comparing XML files

R

Rumpa

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>

Thanks,
Rumpa
 
A

attn.steven.kuo

Rumpa said:
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::Deep;

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"
);
 
B

Bart Lateur

Rumpa said:
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.

Take a look at the module XML::Diff. It might do what you want.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top