Fetch Data from C# to Tree structure XML Sheet

Step 1: Create XML Sheet As shown in below: 
  1. <?xml version="1.0" encoding="UTF-8" standalone="no"?>  
  2. <FORMP2:Form  
  3.     xmlns:FORMP2="http://incometaxindiaefiling.gov.in/FORMP2"  
  4.     xmlns:F15CA="http://incometaxindiaefiling.gov.in/F15CA"  
  5.     xmlns:FORM15CA="http://incometaxindiaefiling.gov.in/Form15CA"  
  6.     xmlns:Form="http://incometaxindiaefiling.gov.in/common"  
  7.     xmlns:FormCommon="http://incometaxindiaefiling.gov.in/Form/Common"  
  8.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://incometaxindiaefiling.gov.in/FORMP2 form.form15CA.xsd ">  
  9.     <FORM15:Form15>  
  10.         <Form:CreationInfo>  
  11.             <Form:SWVersionNo>string</Form:SWVersionNo>  
  12.             <Form:SWCreatedBy>string</Form:SWCreatedBy>  
  13.             <Form:XMLCreatedBy>string</Form:XMLCreatedBy>  
  14.             <Form:XMLCreationDate>2015-02-19</Form:XMLCreationDate>  
  15.             <Form:IntermediaryCity>string</Form:IntermediaryCity>  
  16.         </Form:CreationInfo>  
  17.     </FORM15:Form15>  
  18. </FORMP2:Form>  
 Step 2: C# Code. 
  1. string PATH = Server.MapPath("My.xml");  
  2. //If there is no current file, then create a new one  
  3. if (!System.IO.File.Exists(PATH)) {} else //If there is already a file  
  4. {  
  5.     XDocument doc = XDocument.Load(PATH);  
  6.     // Add a new attribute.  
  7.     foreach(XElement el in doc.Root.Elements()) {  
  8.         XNamespace ns15 = el.GetNamespaceOfPrefix("FORM15");  
  9.         XNamespace ns16 = el.GetNamespaceOfPrefix("F15CA");  
  10.         doc.Root.Elements(ns15 + "Form15CA").Descendants(ns16 + "CreationInfo");  
  11.         foreach(XElement ele in doc.Root.Elements(ns15 + "Form15").Descendants(ns16 + "CreationInfo")) {  
  12.             XNamespace nsE80 = el.GetNamespaceOfPrefix("Form");  
  13.             //ele.SetElementValue(nsE80 + "SWVersionNo", "10");  
  14.             //ele.SetElementValue(nsE80 + "SWCreatedBy", "20");  
  15.             //ele.SetElementValue(nsE80 + "XMLCreationDate", DateTime.Now);  
  16.             //ele.SetElementValue(nsE80 + "IntermediaryCity", "Delhi");  
  17.             foreach(XElement element in ele.Elements())  
  18.             if (element.Name == (nsE80 + "SWVersionNo")) element.Value = "1";  
  19.             else if (element.Name == (nsE80 + "SWCreatedBy")) element.Value = "DIT-EFILING-JAVA";  
  20.             else if (element.Name == (nsE80 + "XMLCreatedBy")) element.Value = "DIT-EFILING-JAVA";  
  21.             else if (element.Name == (nsE80 + "XMLCreationDate")) element.Value = DateTime.Now.ToString("dd-MM-yyyy");  
  22.             else if (element.Name == (nsE80 + "IntermediaryCity")) element.Value = "Delhi";  
  23.         }  
  24.     }  
  25. }