I assume this is a followup to your previous post "Run a perl code on all input files and have the results in different output files", so what you've shown here is the Perl data structure returned by TAP3::Tap3edit's $tap3->structure run through XML::Dumper. That module allows me to parse back the XML into the data structure I show below (anonymized, in case this happens to be real data? Update: SaraMirabi confirmed in the CB that it is fake data) - it would have been better if you'd showed us the Perl data structure to begin with, using Data::Dumper or Data::Dump.

I think it would be best if you didn't rely on munging the output of XML::Dumper, but instead build the XML output from the Perl data structure yourself, because that gives you full control over the produced XML. Personally, although it's a bit more verbose, I prefer to write XML with XML::LibXML and some helper functions. The following is an example of how one might go about that, the idea being that you can adapt this however you need.

Update: Significantly simplified toxml and made it more flexible (output is unchanged).

#!/usr/bin/env perl use warnings; use strict; use open qw/:std :utf8/; use XML::LibXML; my $data = { employee => [ { "************" => "M", age => { dob => "01-04-1993" }, department => { departmentname => "Operations", title => "Manager" }, location => { town => { county => "Somewhere", name => "Someplace" } }, name => { forename => "John", surname => "Doe" }, }, { "************" => "M", age => { dob => "12-12-1979" }, department => { departmentname => "Internet", title => "Developer" }, location => { town => { county => "Somewhere", name => "Othertown" } }, name => { forename => "Jane", surname => "Doe" }, } ] }; my $doc = XML::LibXML::Document->createDocument('1.0', 'UTF-8'); toxml($doc, 'data', $data); print $doc->toString(1); sub toxml { my ($parent, $name, $data) = @_; my @args = $name=~/\A\w+\z/ ? ($name) : ('value', name=>$name); if ( ref $data eq 'HASH' ) { my $el = newel($parent, @args); toxml($el, $_, $data->{$_}) for sort keys %$data; } elsif ( ref $data eq 'ARRAY' ) { toxml(ref eq 'ARRAY' ? newel($parent, @args) : $parent, $name, $_) for @$data; } elsif ( ref $data ) { die "Can't handle $data (yet)" } else { newel($parent, @args)->appendText($data) } } sub newel { my ($parent, $name, %attrs) = @_; my $el = $parent->ownerDocument->createElement($name); $el->setAttribute( $_ => $attrs{$_} ) for keys %attrs; if ( $parent->nodeType==XML_DOCUMENT_NODE ) { $parent->setDocumentElement($el) } else { $parent->appendChild($el) } return $el; } __END__ <?xml version="1.0" encoding="UTF-8"?> <data> <employee> <value name="************">M</value> <age> <dob>01-04-1993</dob> </age> <department> <departmentname>Operations</departmentname> <title>Manager</title> </department> <location> <town> <county>Somewhere</county> <name>Someplace</name> </town> </location> <name> <forename>John</forename> <surname>Doe</surname> </name> </employee> <employee> <value name="************">M</value> <age> <dob>12-12-1979</dob> </age> <department> <departmentname>Internet</departmentname> <title>Developer</title> </department> <location> <town> <county>Somewhere</county> <name>Othertown</name> </town> </location> <name> <forename>Jane</forename> <surname>Doe</surname> </name> </employee> </data>

In reply to Re: removing perldata , hashref from XML file (updated) by haukex
in thread removing perldata , hashref from XML file by SaraMirabi

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.