Manipulate XML File Continous STRING by each Order Line using SHELL

heres sample File:

<?xml version="1.0"?>
<!DOCTYPE cXML SYSTEM "www"><cXML..............................................
<OrderRequest>USE UNIX.com</Extrinsic><Extrinsic name="UniqueName">Peter@UNIX.com</Extrinsic><Extrinsic name="ContractingEntity">UNIX AMERICA</Extrinsic></OrderRequestHeader><ItemOut lineNumber="1" quantity="1" ....</ItemOut><ItemOut lineNumber="2" quantity="1" ......<Comments>UNIX IS GREAT</Comments></ItemOut><ItemOut lineNumber="3"......</Comments></ItemOut></OrderRequest></Request></cXML>

how I want it:

<?xml version="1.0"?>
<!DOCTYPE cXML SYSTEM "www"><cXML..............................................
USE UNIX.com</Extrinsic><Extrinsic name="UniqueName">Peter@UNIX.com</Extrinsic><Extrinsic name="ContractingEntity">UNIX AMERICA</Extrinsic></OrderRequestHeader>
<ItemOut lineNumber="1" quantity="1" ..................................</ItemOut>
<ItemOut lineNumber="2" quantity="2" ......<Comments>UNIX IS GREAT</Comments></ItemOut>
<ItemOut lineNumber="3".....................................</Comments></ItemOut>
</OrderRequest></Request></cXML>

what I use:

 
sed -i $file -e 's/<\/ItemOut>/&\n/g;'

problems:

1)This do not bring linenumber 1 to new line
2)Larger files behave weird, (but there is a pattern, every 10 lines tags go into diffent line, there is a big space every 10 lines) (IF the file is LARGE)
3)Every <ItemOut lineNumber=".... should be a new line and end with </ItemOut> (As per BLUE above)
4) OPEN TAG <ItemOut and CLOSED TAG </ItemOut> always exists EXISTS in the file
5) There are Multiple XML files and I loop through each file using $i as in the code above..

Thanks
pete

One way.., assume x.xml has the contents...you have to quote the end of line and hit return key, then on next line close the sed expression

 cat x.xml | sed -e 's/<\/ItemOut>/ \    
/g'

Or using awk:

awk '{gsub("</ItemOut>","&"RS)}1' file.xml

This is working BUT when I have a LARGE file it behaves weird

the tags are not proper in a pattern meaning

it follows pattern for 10 lines then RANDOMLY another tag gets cut off then there is a space THEN it works fine again the PATTTERN Repeats

 
<ItemOUT ........................................</ItemOut>
<ItemOUT ........................................</ItemOut>
<ItemOUT ........................................</ItemOut>
<ItemOUT ........................................</ItemOut>
<ItemOUT ............................<sometag>

............</ItemOut>
*****SPACE*****SPACE****HERE***
<ItemOUT ........................................</ItemOut>
<ItemOUT ........................................</ItemOut>
<ItemOUT ........................................</ItemOut>
<ItemOUT ........................................</ItemOut>
<ItemOUT ........................................</ItemOut>
<ItemOUT ............................<sometag>
............</ItemOut>
<ItemOUT ........................................</ItemOut>
<ItemOUT ........................................</ItemOut>
 <ItemOUT ........................................</ItemOut>
<ItemOUT ........................................</ItemOut>
 
*****SPACE*****SPACE****HERE***
 
<ItemOUT ........................................</ItemOut>
<ItemOUT ........................................</ItemOut>
 <ItemOUT ........................................</ItemOut>
<ItemOUT ............................<sometag>
............</ItemOut>
<ItemOUT ........................................</ItemOut>
<ItemOUT ........................................</ItemOut>
<ItemOUT ........................................</ItemOut>
<ItemOUT ........................................</ItemOut>

it does this for LARGE files dont know why? when I use any of sed and awk commands above

For Smaller files with 20-30 lines its ok , but with larger files it does not work..

Any advices please...