Regular Expressions: Can't quite figure this problem out

Robert Dailey rcdailey at
Tue Sep 25 02:37:20 CEST 2007


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


The regular expression would convert the XML above into:


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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the Python-list mailing list