public List <RelatedLetter> getRelatedLetters() { List <RelatedLetter> lstRelatedLetter = new List <RelatedLetter>(); var q = (from s in xmlDoc.Descendants() where s.Name.LocalName == "RelatedLetter" select s).ToList(); foreach (var item in q) { RelatedLetter rl = new RelatedLetter(); XElement xelmentRelatedLetterDateTime = item.Element("RelatedLetterDateTime"); LetterDateTime letterDateTime = new LetterDateTime(); letterDateTime._LetterDateTime = xelmentRelatedLetterDateTime.Value; letterDateTime.Any = (string)xelmentRelatedLetterDateTime.Attribute("Any"); letterDateTime.ShowAs = (string)xelmentRelatedLetterDateTime.Attribute("ShowAs"); rl.RelatedLetterDateTime = letterDateTime; XElement xelmentRelatedLetterNO = item.Element("RelatedLetterNO"); LetterNo letterno = new LetterNo(); letterno._LetterNo = xelmentRelatedLetterNO.Value; letterno.Any = (string)xelmentRelatedLetterNO.Attribute("Any"); rl.RelatedLetterNO = letterno; XElement xelmentRelatedLetterSender = item.Element("RelatedLetterSender"); Sender sender = new Sender(); sender.Any = (string)xelmentRelatedLetterSender.Attribute("Any"); sender.Code = (string)xelmentRelatedLetterSender.Attribute("Code"); sender.Department = (string)xelmentRelatedLetterSender.Attribute("Department"); sender.Name = (string)xelmentRelatedLetterSender.Attribute("Name"); sender.Organization = (string)xelmentRelatedLetterSender.Attribute("Organization"); sender.Position = (string)xelmentRelatedLetterSender.Attribute("Position"); rl.RelatedLetterSender = sender; XElement xelmentRelationType = item.Element("RelationType"); RelationType relationType = new RelationType(); relationType.Any = (string)xelmentRelationType.Attribute("Any"); relationType.code = (string)xelmentRelationType.Attribute("code"); relationType.Name = (string)xelmentRelationType.Attribute("Name"); rl.RelationType = relationType; lstRelatedLetter.Add(rl); } return(lstRelatedLetter); }
public void addRelatedLetter(RelatedLetter relatedLetter) { System.Xml.Linq.XElement q; q = (from s in xmlDoc.Descendants() where s.Name.LocalName == "RelatedLetters" select s).FirstOrDefault(); XElement xelement = new XElement("RelatedLetter", null); XElement xRelatedLetterDateTime = new XElement("RelatedLetterDateTime", relatedLetter.RelatedLetterDateTime._LetterDateTime, new XAttribute("ShowAs", relatedLetter.RelatedLetterDateTime.ShowAs), new XAttribute("Any", relatedLetter.RelatedLetterDateTime.Any)); XElement xRelatedLetterNO = new XElement("RelatedLetterNO", relatedLetter.RelatedLetterNO._LetterNo, new XAttribute("Any", relatedLetter.RelatedLetterNO.Any)); XElement xRelatedLetterSender = new XElement("RelatedLetterSender", null, new XAttribute("Any", relatedLetter.RelatedLetterSender.Any), new XAttribute("Code", relatedLetter.RelatedLetterSender.Code), new XAttribute("Department", relatedLetter.RelatedLetterSender.Department), new XAttribute("Name", relatedLetter.RelatedLetterSender.Name), new XAttribute("Organization", relatedLetter.RelatedLetterSender.Organization), new XAttribute("Position", relatedLetter.RelatedLetterSender.Position)); XElement xRelationType = new XElement("RelationType", null, new XAttribute("Any", relatedLetter.RelationType.Any), new XAttribute("code", relatedLetter.RelationType.code), new XAttribute("Name", relatedLetter.RelationType.Name)); xelement.Add(xRelatedLetterDateTime); xelement.Add(xRelatedLetterNO); xelement.Add(xRelatedLetterNO); xelement.Add(xRelatedLetterSender); xelement.Add(xRelationType); q.Add(xelement); }