Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

XMLPrettyPrint: Simple Xml Pretty Print In Perl

DZone's Guide to

XMLPrettyPrint: Simple Xml Pretty Print In Perl

·
Free Resource

### begin_: file metadata
    ### 
  
   
    ### main:
    ###   - name    : XMLPrettyPrint: simple xml pretty print in perl
    ###     desc    : use perl with XML::Twig library to print indented xml
    ###     date    : created="Thu 2005-12-01 11:08:15"
    ###     last    : lastmod="Thu 2005-12-01 11:22:34"
    ###     lang    : perl
    ###     tags    : perl xml indent formatted pretty string cfPrettyPrint
    ### 
  

### begin_: init perl
    use strict;
    use warnings;
    use XML::Twig;

### begin_: init vars
    my  $sXML  = join "", (
  
   );

    ### init params
    my  $params = [qw(none nsgmls nice indented record record_c)];
    my  $sPrettyFormat  = $params->[3] || 'none';

### begin_: process
    my  $twig= new XML::Twig;
    $twig->set_indent(" "x4);
    $twig->parse( $sXML );
    $twig->set_pretty_print( $sPrettyFormat );
    $sXML      = $twig->sprint;

### begin_: output
    print $sXML;

### begin_: sample data
    1;
    __END__

   
    Homer
   
   
    Simpson
   
   
    Barney
   
   
    Rubble
   
   
    Betty
   
   
    Rubble
   
   
Topics:

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}