/// <summary> /// Builds a document from the corresponding response xml node /// </summary> /// <param name="node">response xml node</param> /// <returns>populated document</returns> public T ParseDocument(XElement node) { var doc = activator.Create(); foreach (var field in node.Elements()) { string fieldName = field.Attribute("name").Value; propVisitor.Visit(doc, fieldName, field); } return(doc); }
/// <summary> /// Builds a document from the corresponding response xml node /// </summary> /// <param name="node">response xml node</param> /// <param name="fields">document fields</param> /// <returns>populated document(s)</returns> public IEnumerable <T> ParseDocument(XElement node) { IList <T> docs = new List <T>(); IList <XElement> children = new List <XElement>(); var doc = activator.Create(); foreach (var field in node.Elements()) { if (field.HasElements && string.Equals(field.Name.LocalName, "doc", System.StringComparison.OrdinalIgnoreCase)) { children.Add(field); } else { string fieldName = field.Attribute("name").Value; propVisitor.Visit(doc, fieldName, field); } } if (children.Count > 0) { foreach (var child in children) { var newDoc = ShallowClone.Clone(doc); foreach (var field in child.Elements()) { string fieldName = field.Attribute("name").Value; propVisitor.Visit(newDoc, fieldName, field); } docs.Add(newDoc); } } else { docs.Add(doc); } return(docs); }