sed ksh remove newline between 2 containers

If we assume that each line between the {} container is an XML document then What I want to remove the newline character from all lines within each container to have one XMDL document per line I wrote a bit of sed after trawling the web:

e.g.

#!/bin/sed -nf

H
/}/ {
x
s/\n//g
p
}

This process is not quite behaving how I expect in that some of the lines are mixed up between the containers

File before being passed to sed

{dwfglsdfsdfsdfsdfsdfsdfsdfsdfsdf\n
dgdgdgdgdgdgdgdgdgdgdg\n
dfgsdfgsdfgsdfg}\n
\n
{sdgfsdgggggggggggggggg\n
ggggggggggggggggggggg\n
gggggggggggggggggggggsdf\n
d}\n
\n
{asdfasdfasdfasd\n
asdfasdfasdfasdf\n
sfasdfasdfasdf\n
sdfasdfasdfasdf}\n
\n

File after sed (is what I am hoping for with the only \n after the end }):

{dwfglsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfdgdgdgdfgsdfgsdfgsdfg}\n
{sdgfsdgggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggsdfd}\n
{asdfasdfasdfasdasdfasdfasdfasdfsfasdfasdfasdfsdfasdfasdfasdf}\n

what I am getting is:

{dwfglsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfdgdgdgdgdgdgdgdgdgdgdg
dfgsdfgsdfgsdfg}\n
{sdgfsdgggggggggggggggggggggggggggggggggggggggggggggggggsdfd}{asdfasdfasdfasdasdfasdfasdfasdfsfasdfasdfasdfsdfasdfasdfasdf}\n

The lines are long so I would expect wrapping per one line but not to see a container }{ being embedded within a line without a newline after the enclosing }

Try the following as your sed script... and just use sed -f (no -n option)

/[{]/b a
b
:a
/[}]/ {
s/\n//
b
}
s/\n//
N
b a

nawk '
{
if ("$NF" != "" ) {
a=a" "$0 ;
}
if (!NF && a) {
print a ; a=""
}
} ' inputfiile

Thanks guys,

I tested both solutions and the sed solution produced consistent results whereas the nawk solution was slightly inconsistant with each line in that in some cases it added a space to the start of some of the records.

Thanks for your help guys, much appreciated!

Jim