Naresh Ramaswamy wrote:

> 
> I feel the above solution is quite clumsy, Please suggest me a better 
> solution for it.

Use a pull parser and convert the XML into a more sensible data structure.

A pull parser also makes it easier to trigger events based on elements. 
Maybe you can skip the restructuring and directly work with the element 
stream.

I think my Dr. Dobbs article may still be relevant:

http://www.jamesbritt.com/2007/4/14/transforming-xml-the-rexml-pull-parser


-- 
James Britt

www.jamesbritt.com           - Playing with Better Toys
www.ruby-doc.org             - Ruby Help & Documentation
www.rubystuff.com            - The Ruby Store for Ruby Stuff