Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

> Now I'm trying to stores these files in an array and compare them.
> How can one store the entire file in an array?
XML is a tree structure and a single array isn't really designed to be the most intuitive or simple way to store a tree.

> Now I have to compare the two XML files
Comparing XML files is a problem many people need to solve these days so a CPAN search might help. After looking through the modules in the CPAN search results and some experimenting I came up with XML::SemanticDiff. The sample code and output might give further ideas on how the module might be applied to the posted problem.

use strict; use warnings; use XML::SemanticDiff; my $x = XML::SemanticDiff->new; my @diffs = $x->compare( <<EOXML_1, <top> <firstTag>abc</firstTag> <secondTag>def</secondTag> <thirdTag>ghi</thirdTag> </top> EOXML_1 <<EOXML_2 <top> <firstTag>abc</firstTag> <secondTag>456</secondTag> <lastTag>ghi</lastTag> </top> EOXML_2 ); foreach my $change (@diffs) { print "$change->{message}\n\tin XPath context $change->{context} +\n"; } __END__ Character differences in element 'secondTag'. in XPath context /top[1]/secondTag[1] Child element 'thirdTag' missing from element '/top[1]'. in XPath context /top[1] Rogue element 'lastTag' in element '/top[1]'. in XPath context /top[1]
Ron

In reply to Re: Comparing two XML files with XML::Simple using FOREACH and IF using by mr_ron
in thread Comparing two XML files with XML::Simple using FOREACH and IF using by gr.d

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (3)
As of 2024-04-20 14:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found