There is a inbuilt function called XMLElement in DataDirect Query Builder for XML that does what I want. So, I wrote my own UDF that woudl do the same thing. But, I am not sure what the effect on performance would be if I called this UDF over and over again for each element that I needed to create.
Here is a link to the XMLElement function.
http://media.datadirect.com/download/docs/connectsqlxml/csxug/sql_xml_grammar.html
http://media.datadirect.com/download/docs/connectsqlxml/csxug/sqlxml_tutorial.html
The solution with the COALESCE and ISNULL with the CASE looks a lot better than the combination I have with COALESCE and NULLIF. But then again, when I have child elements, then the CASE statement combination also get cumbersome, since I have insert the same combination into the ISNULL statement recursively!
Thank you.
Viji