Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Comparing XML files

Reply
Thread Tools

Comparing XML files

 
 
Rumpa
Guest
Posts: n/a
 
      08-09-2005
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
 
Reply With Quote
 
 
 
 
attn.steven.kuo@gmail.com
Guest
Posts: n/a
 
      08-09-2005
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

 
Reply With Quote
 
 
 
 
Bart Lateur
Guest
Posts: n/a
 
      08-09-2005
Rumpa wrote:

>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:iff. It might do what you want.

--
Bart.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Comparing 2 XML files need some suggestions please Rishi Dhupar Perl Misc 2 04-15-2005 02:58 PM
Comparing huge XML Files junnuthala Perl Misc 10 02-25-2005 10:00 PM
command line tool for comparing XML files Corno XML 8 02-22-2004 10:49 AM
New release of ExamXML visual tool for comparing and merging XML files. Joe XML 0 01-08-2004 11:55 AM
New release of ExamXML (comparing XML files) Joe HTML 0 10-21-2003 09:39 AM



Advertisments