Perl/xml query

My perl script generates an xml schema :-

<fullletter>
<CASE_EPIS>00036</CASE_EPIS>
-
   <letter>
      <IMAGENAME>02_20100423124541</IMAGENAME>
      <RUNDATE>2010-04-23 12:04:41</RUNDATE>
       <LETTERTYPE>LOI2</LETTERTYPE>

   </letter>
-    <service> </service>
       <service>
           <NTV_SEQUENCE>26</NTV_SEQUENCE>
-
           <NTV_DISPLAY_VALUE>Need start date </NTV_DISPLAY_VALUE>
      </service>
       <service> </service>
     
</fullletter>


I need to remove the empty service tags <service> </service>
what would be the regular expression for the same..
Appreciate assistance.

Thanks,
Craig
CraigttyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

kawasCommented:

my $file = <<EOF;
<fullletter>
<CASE_EPIS>00036</CASE_EPIS>

   <letter>
      <IMAGENAME>02_20100423124541</IMAGENAME>
      <RUNDATE>2010-04-23 12:04:41</RUNDATE>
       <LETTERTYPE>LOI2</LETTERTYPE>

   </letter>
    <service> </service>
       <service>
           <NTV_SEQUENCE>26</NTV_SEQUENCE>

           <NTV_DISPLAY_VALUE>Need start date </NTV_DISPLAY_VALUE>
      </service>
       <service> </service>
     
</fullletter>
EOF

use XML::Simple;
use Data::Dumper;

my $xs = XML::Simple->new(NormaliseSpace => 2, KeepRoot => 1, ForceArray=>1, SuppressEmpty => 1);
my $ref = $xs->XMLin($file);
print Dumper($ref);

print $xs->XMLout($ref);

Open in new window

0
kawasCommented:
more detail on this solution here: http://ekawas.blogspot.com/2010/04/getting-rid-of-empty-xml-elements-using.html

I added some comments and cleaned up the code
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CraigttyAuthor Commented:
$text =~ s|<service>\n  </service>||sog; This removed the empty service tags <service> </service>
0
kawasCommented:
sure, but depending on how the XML is created that tag wont always serialize like that...
0
CraigttyAuthor Commented:
The perl script creates a standard xml structure.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Perl

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.