public bool AddNode(CommentModel model) { var newComment = new XmlElementProvider() { Key = "comment", Value = "", Attributes = new List <XAttribute>() { new XAttribute("id", Guid.NewGuid().ToString()) }, Children = new List <XmlElementProvider>() { new XmlElementProvider() { Key = "author", Value = model.Author.username, }, new XmlElementProvider() { Key = "date", Value = model.Date.ToString() }, new XmlElementProvider() { Key = "content", Value = model.Content, } } }; return(AddNode("comments", newComment)); }
public static XmlElementProvider Recursive_XmlElementProvider(XElement originalNode, bool isRoot = true) { if (originalNode == null) { return(null); } var xElement = new XmlElementProvider() { Key = originalNode.Name.ToString(), Value = !isRoot ? originalNode.Value : "", Attributes = originalNode.Attributes().ToList(), Children = new List <XmlElementProvider>() }; if (originalNode.Nodes().Any()) { foreach (var node in originalNode.Elements()) { xElement.Children.Add(Recursive_XmlElementProvider(node, false)); } } return(xElement); }
public virtual IEnumerable <XmlElementProvider> ReadNode(String key) { if (OpenedDocument?.Root == null) { return(new List <XmlElementProvider>()); } var comments = OpenedDocument.Descendants(key).Elements(); return(!comments.Any() ? new List <XmlElementProvider>() : comments.Select(node => XmlElementProvider.Recursive_XmlElementProvider(node))); }
public static XElement Recursive_ConvertToXElement(XmlElementProvider originalNode) { if (originalNode.Key == null && !originalNode.Key.Trim().Any() && originalNode.Value == null) { return(null); } var xElement = new XElement(originalNode.Key, originalNode.Value, originalNode.Attributes); if (originalNode.Children.Any()) { foreach (var node in originalNode.Children) { xElement.Add(Recursive_ConvertToXElement(node)); } } return(xElement); }