DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
  • Refcardz
  • Trend Reports
  • Webinars
  • Zones
  • |
    • Agile
    • AI
    • Big Data
    • Cloud
    • Database
    • DevOps
    • Integration
    • IoT
    • Java
    • Microservices
    • Open Source
    • Performance
    • Security
    • Web Dev
DZone >

XMLPrettyPrint: Simple Xml Pretty Print In Perl

Snippets Manager user avatar by
Snippets Manager
·
Dec. 02, 05 · · Code Snippet
Like (0)
Save
Tweet
1.85K Views

Join the DZone community and get the full member experience.

Join For Free

### 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__
HomerSimpsonBarneyRubbleBettyRubble
Perl (programming language)

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • How to Handle Early Startup Technical Debt (Or Just Avoid it Entirely)
  • 3 Predictions About How Technology Businesses Will Change In 10 Years
  • Password Authentication. How to Correctly Do It.
  • Exporting and Importing Projects in Eclipse

Comments

Partner Resources

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • MVB Program
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends:

DZone.com is powered by 

AnswerHub logo