We can add attributes to different elements of XML object by using addAttribute() function. We will try with different examples to add attributes at different level of child node. We used asXML function to display XML string. We have used our sample xml file for this. Here is the code.