There is a MySQL XML dump that contains data in the following format:
<row> <field name='column1'>Homer</field> <field name='column2'>Homer Simpson</field> <field name='column3'>Nuclear Systems Operation</field> </row>

I would like to key in on the 'field name' or convert the above to the following format:
<row> <column1>Homer</column1> <column2>Homer Simpson</column2> <column3>Nuclear Systems Operation</column3> </row>

This is the code I currently have. It will work for the second 'converted' version of the XML output.:
my $xml = new XML::Simple (KeyAttr=>'row'); my $data = $xml->XMLin("Employee.xml"); foreach my $e (@{$data->{row}}) { print "cn: ", $e->{column1}, "\n"; print "sn: ", $e->{column2}, "\n"; print "Department: ", $e->{column3}, "\n"; print "\n"; }


Ideally, I would like to skip the conversion process and just be able to key in on the 'field name' entry. If this is not possible, How would I first convert the file replace 'field name='column1' with just 'column1' and '/field' with '/column1'? I've tried cheating with a system command & perl one-liner within my script to do a search and replace. It didn't work as expected and was pretty fugly.

In reply to Change MySQL 5.0 XML output to 4.0 output by rycher

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.