Monday, 16 September 2013

Updating XML with linque xml



string XMLFile1 =HttpContext.Current.Server.MapPath("~/XMLFiles/College.xml");
            XDocument doc = XDocument.Load(XMLFile1);
            IEnumerable<XElement> rech =
                                 from el in doc.Root.Elements("Table")
                                 where (string)el.Element("clg_code") == collegeCode
                                 select el;
            if (rech.Count() != 0)
            {
                foreach (XElement el in rech)
                {
                    
                    el.Element("clg_code").SetValue(collegeCode);
                    el.Element("clg_name").SetValue(collegeName);
                    el.Element("clg_state").SetValue(stateId);
                    el.Element("clg_district").SetValue(districtId);
                    el.Element("clg_university").SetValue(universityId);
                    el.Element("clg_address").SetValue(address);
                    el.Element("clg_pincode").SetValue(pincode);
                    el.Element("clg_nearestplace1").SetValue(nearPlace1);
                    el.Element("clg_nearestplace2").SetValue(nearPlace2);
                    el.Element("clg_establishmentyear").SetValue(year);
                    el.Element("clg_contactno1").SetValue(contactNo1);
                    el.Element("clg_contactno2").SetValue(contactNo2);
                    el.Element("clg_contactno3").SetValue(contactNo3);
                    el.Element("clg_website").SetValue(website);
                    el.Element("clg_email1").SetValue(email1);
                    el.Element("clg_email2").SetValue(email2);
                    el.Element("clg_email3").SetValue(email3);
                    el.Element("clg_personname").SetValue(contactPerson);
                    el.Element("clg_persondesigination").SetValue(designation);
                    el.Element("clg_personmobileno").SetValue(cpMobileNo);
                    el.Element("clg_personemail").SetValue(cpemail);
                    el.Element("clg_approved").SetValue(status);

                  
                }
            }
            doc.Save(XMLFile1);

No comments:

Post a Comment