How to pretty-print XML with a regular expression?

A

Andrew Montgomery

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!
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top