public void addOtherReceiver(OtherReceiver receiver) { System.Xml.Linq.XElement q; q = (from s in xmlDoc.Descendants() where s.Name.LocalName == "OtherReceivers" select s).FirstOrDefault(); XElement xelement = new XElement("OtherReceiver", null); XAttribute xAttAny = new XAttribute("Any", receiver.Any == null?"": receiver.Any); XAttribute xAttCode = new XAttribute("Code", receiver.Code); XAttribute xAttDepartment = new XAttribute("Department", receiver.Department == null ? "" : receiver.Department); XAttribute xAttName = new XAttribute("Name", receiver.Name == null ? "" : receiver.Name); XAttribute xAttOrganization = new XAttribute("Organization", receiver.Organization == null ? "" : receiver.Organization); XAttribute xAttPosition = new XAttribute("Position", receiver.Position == null ? "" : receiver.Position); XAttribute xAttReceiveType = new XAttribute("ReceiveType", receiver.ReceiveType); xelement.Add(xAttAny); xelement.Add(xAttCode); xelement.Add(xAttDepartment); xelement.Add(xAttName); xelement.Add(xAttOrganization); xelement.Add(xAttPosition); xelement.Add(xAttReceiveType); q.Add(xelement); }
public List <OtherReceiver> getOtherRecivers() { List <OtherReceiver> lstReceiver = new List <OtherReceiver>(); var q = (from s in xmlDoc.Descendants() where s.Name.LocalName == "OtherReceiver" select s).ToList(); foreach (var item in q) { OtherReceiver rc = new OtherReceiver(); rc.Any = (string)item.Attribute("Any"); rc.Code = (string)item.Attribute("Code"); rc.Department = (string)item.Attribute("Department"); rc.Name = (string)item.Attribute("Name"); rc.Organization = (string)item.Attribute("Organization"); rc.Position = (string)item.Attribute("Position"); rc.ReceiveType = (string)item.Attribute("ReceiveType"); lstReceiver.Add(rc); } return(lstReceiver); }