SELECT 'nameValue' AS "@name", CAST('<!-- your comment -->' AS XML), 'anotherValue' AS "another", (SELECT 'i' AS "@name", '1' AS "@value" FOR XML PATH('item'), TYPE), (SELECT 'j' AS "@name", '2' AS "@value" FOR XML PATH('item'), TYPE) FOR XML PATH('sample'), ROOT('root')
output
<root> <sample name="nameValue"> <!-- your comment --> <another>anotherValue</another> <item name="i" value="1"></item> <item name="j" value="2"></item> </sample> </root>
/** * @author R * 1+2+3+4 .... + 99+100 = 5050 */ public class Main { /** Creates a new instance of Main */ public Main() {} /** * @param args the command line arguments */ public static void main(String[] args) { System.out.println(recursiveAdd(100)); } public static int recursiveAdd(int upto) { if(upto == 0) return 0; return upto + recursiveAdd(--upto); } }
Recursion can solve some problems that iteration can not achieve. But recursion is not always the fastest way and efficient, it requires more memory than iteration does in most of the cases.