473,387 Members | 1,485 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

How to compare two XML files in perl?

How to compare two files in perl. I have two files as shown below.

Expand|Select|Wrap|Line Numbers
  1. First XML File
  2. <Data>
  3. <indep voltage>
  4.   +1.20000000000e+01
  5. </indep>
  6. <indep current>
  7.   +5.08474576271e-04
  8. </indep>
  9. </Data>
  10.  
  11. Second XML File:
  12. <Data>
  13. <indep voltage>
  14.   +1.20000000000e+01
  15. </indep>
  16. <indep current>
  17.   +5.08474576271e-04
  18. </indep>
  19. </Data>
  20.  
  21.  
I just want to confirm whether Data,indep tags are present with the specified attributes current and voltage.
I don't want whether the values are same.
I am confused to use the modules like XML::Simple and all.
Pls suggest me how to do that. I am newbie in perl. Pls provide me the good example also so that i can understand it.
Sep 23 '10 #1
3 7359
nithinpes
410 Expert 256MB
To compare two XML documents and find the differences, you may make use of XML::SemanticDiff.

The documentation given in CPAN would be sufficient to start with the script. Try it out and if you face any problem, post it here.
Sep 24 '10 #2
Hello nithinpes, I am using XML::SemanticCompare to compare two files. I downloaded that module. But I'm getting the error
can't use an undefined value as an ARRAY reference at C:/Perl/site/lib/XML/SemanticCompare. I didn't get what it means. Can you put some light on that?
My Code is:
Expand|Select|Wrap|Line Numbers
  1.     $file1 = $args[0] . "\\test.xml";
  2.     $file2 = $args[0] . "\\test1.xml";
  3.  
  4.     local $/;
  5.     open(my $in, "<$file1") or die "File1: $!\n";
  6.     my $xml1=<$in>;
  7.     close($in);
  8.     open($in, "<$file2") or die "File2: $!\n";
  9.     my $xml2=<$in>;
  10.     close($in);
  11.  
  12.      #open(my $out, ">output.txt") or die "Output: $!\n";
  13.     # get the diffs
  14.     my $diffs_arrayref = $x->diff($control_xml, $test_xml);
  15.     print @$diffs_arrayref;
  16.     #close($out);
  17.  
Sep 24 '10 #3
Hello nithinpes. I rectified the error. But I don't know how to interpret the output of XML::SemanticCompare->diff() method. Pls put some light on that.
Sep 27 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

44
by: Xah Lee | last post by:
here's a large exercise that uses what we built before. suppose you have tens of thousands of files in various directories. Some of these files are identical, but you don't know which ones are...
4
by: Lad | last post by:
Hi, What is the best method for comparing two files by words? I was thinking about reading files by words and compare them but a word in one file can be linked with a new line character ( \n) and...
2
by: SP | last post by:
Hi All, I need to compare two files line by line and copy the differing lines to a new files. I.e. Compare file1 and file2 line by line. Copy only differing lines to file3. I tried a couple...
8
by: pjsimon | last post by:
I want to compare two files like MS Visual SourceSafe's Show Differences feature. Is there a way to access methods in VB.Net that will let me use existing MS code to show the differences between...
3
by: shona | last post by:
Hi, can any one told me how to compare files with same name but different extension.. for eg. if a.txt & a.doc then ans is same files.. Thanks
0
by: ds81 | last post by:
I am trying to read a large number of image (BMP, JPG) files, and need to know if any are identical. I have been trying to store the hashcodes of the files, so that they then can be compared later. ...
4
by: Clay Hobbs | last post by:
I am making a program that (with urllib) that downloads two jpeg files and, if they are different, displays the new one. I need to find a way to compare two files in Python. How is this done? ...
0
by: norseman | last post by:
Timothy Grant wrote: =================================== If you are on a Unix platform: man cmp man identify man display (ImageMagick) gimp If you use mc (MidnightCommander) the F3 key can...
0
by: zw | last post by:
Hi I have 2 log files, each with a timestamp on the first 2 fields. However, when I do a awk '/ / {print $1,$2}' logs/x.log on a log file, it is complicated by the fact that I also get other...
3
by: Susan StLouis | last post by:
I'm writing a program that can be used to compare files. The program features a select that contains a list of files. After selecting several of the files. a "Biggest" button can be pushed to find...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.