How to pretty-print XML with a regular expression?

Discussion in 'Perl' started by Andrew Montgomery, Sep 17, 2003.

  1. Here's a challenge for all the hard-core regexp writers out there:
    pretty-printing XML in as few regular expressions as possible.
    Basically what I'm looking for is a method of converting this:

    <tag1 attr="value"><tag2 earth="round"><tag3
    bob="youruncle"></tag3><tag4 perl="cool" /></tag2></tag1>

    into this:

    <tag1 attr="value">
    <tag2 earth="round">
    <tag3 bob="youruncle">
    </tag3>
    <tag4 perl="cool" />
    </tag2>
    </tag1>

    with as little code as possible. Thanks!
     
    Andrew Montgomery, Sep 17, 2003
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. VSK
    Replies:
    2
    Views:
    2,398
  2. edw
    Replies:
    2
    Views:
    9,587
  3. akbar

    custom xml pretty print

    akbar, Nov 20, 2005, in forum: Python
    Replies:
    1
    Views:
    420
    Diez B. Roggisch
    Nov 20, 2005
  4. Pk Z.
    Replies:
    3
    Views:
    243
    Mike Dalessio
    Jan 13, 2011
  5. Phlip
    Replies:
    2
    Views:
    1,072
    japisoft
    May 7, 2012
Loading...

Share This Page