Regular Expressions: Can't quite figure this problem out

Robert Dailey rcdailey at gmail.com
Mon Sep 24 20:37:20 EDT 2007


Hi,

I'm attempting to create a regular expression that removes redundancy in
empty XML elements. For example:

<root></root>

The regular expression would convert the XML above into:

<root/>

And another complex example:

<root><frame type="image"><action></action></frame></root>

would be:

<root><frame type="image"><action/></frame></root>


So far I've been unsuccessful in creating a regular expression to do this.
Below are outlined various guarantees:

- The XML to be parsed shall have NO comments in it
- The XML to be parsed shall have NO whitespace (spaces, tabs, carriage
returns, etc) between elements. The examples above represent what this
means.

Thanks.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20070924/9885908f/attachment.html>


More information about the Python-list mailing list