Sed command to clean xml tag

Hi,
Can someone help me come up with a generic sed command to clean a tag off its attributes?

For eg.
Input String - <tag attrib=new>This String</tag>
should undergo a sed transformation to get
Output String - <tag >This String</tag>

This works -
echo "<tag attrib=new>This</tag>" | sed -e 's/\([^<\/A-Za-z]\)[^>]*>/\1>/g'

<tag >This</tag>

However, the moment i add a space in there - it goes for a toss
echo "<tag attrib=new>This String</tag>" | sed -e 's/\([^<\/A-Za-z]\)[^>]*>/\1>/g'

<tag >This >

Resolved the above issue using a single replace -
echo "<tag attrib=new>This String</tag>" | sed -e 's/\([^<\/A-Za-z]\)[^>]*>/\1>/'

<tag >This String</tag>

However, it does not handle the scenario -
echo " <tag attrib=new>This String</tag>" | sed -e 's/\([^<\/A-Za-z]\)[^>]*>/\1>/'

>This String</tag>

Any inputs on this will be of great help.

Hi,

try:

Code:

echo "<tag attrib=new>This lousy winter day</tag>" \
    | sed -e 's#<\([^ ]*\)[^>]*>\([^<]*\)\(</\1>\)#<\1>\2\3#g'

Output:

<tag>This lousy winter day</tag>

HTH Chris

Wow. That approach works great. Thanks Chris.
Also, can you help me understand - how could i have changed the original approach to take care of this - 'cos i have a feeling that i was nearly there (or maybe not!!)

Simply the "g" at the end of the sed command. You want sed
to only execute one substitution, the first.

Your corrected code:

echo "<tag attrib=new>This String</tag>" \
    | sed -e 's/\([^<\/A-Za-z]\)[^>]*>/\1>/'

Output:

<tag >This String</tag>