public bool ContainsChild(NodeTree nt) { if (ContainsChildLoop(this.Children, nt)) { return(true); } else { return(false); } }
private bool ContainsChildLoop(ObservableCollection <NodeTree> childList, NodeTree ntc) { bool hasChild = false; foreach (var c in childList) { if (c == ntc) { return(true); } if (c.Children.Count > 0) { if (ContainsChildLoop(c.Children, ntc)) { return(true); } } } return(hasChild); }
// Export OPML public XmlDocument WriteOpml(NodeTree serviceRootNode) { XmlDocument xdoc = new(); XmlDeclaration xdec = xdoc.CreateXmlDeclaration("1.0", "UTF-8", null); xdoc.AppendChild(xdec); XmlElement eleRoot = xdoc.CreateElement(string.Empty, "opml", string.Empty); xdoc.AppendChild(eleRoot); XmlAttribute verAttr = xdoc.CreateAttribute("version"); verAttr.Value = "1.0"; eleRoot.SetAttributeNode(verAttr); XmlElement eleHead = xdoc.CreateElement(string.Empty, "head", string.Empty); XmlElement eleTitle = xdoc.CreateElement(string.Empty, "title", string.Empty); eleTitle.InnerText = "Exported at " + DateTime.Now.ToString(); eleHead.AppendChild(eleTitle); eleRoot.AppendChild(eleHead); XmlElement eleBody = xdoc.CreateElement(string.Empty, "body", string.Empty); eleRoot.AppendChild(eleBody); foreach (NodeTree nt in serviceRootNode.Children) { if (nt is NodeFeed) { XmlElement eleOutline = xdoc.CreateElement(string.Empty, "outline", string.Empty); eleBody.AppendChild(eleOutline); XmlAttribute typeAttr = xdoc.CreateAttribute("type"); typeAttr.Value = "rss"; eleOutline.SetAttributeNode(typeAttr); XmlAttribute textAttr = xdoc.CreateAttribute("text"); textAttr.Value = nt.Name; eleOutline.SetAttributeNode(textAttr); XmlAttribute titleAttr = xdoc.CreateAttribute("title"); titleAttr.Value = nt.Name; eleOutline.SetAttributeNode(titleAttr); XmlAttribute xmlUriAttr = xdoc.CreateAttribute("xmlUrl"); xmlUriAttr.Value = (nt as NodeFeed).EndPoint.AbsoluteUri; eleOutline.SetAttributeNode(xmlUriAttr); if ((nt as NodeFeed).SiteUri is not null) { XmlAttribute htmlUriAttr = xdoc.CreateAttribute("htmlUrl"); htmlUriAttr.Value = (nt as NodeFeed).SiteUri.AbsoluteUri; eleOutline.SetAttributeNode(htmlUriAttr); } continue; } if (nt is NodeFolder) { XmlElement eleOutline = xdoc.CreateElement(string.Empty, "outline", string.Empty); eleBody.AppendChild(eleOutline); XmlAttribute textAttr = xdoc.CreateAttribute("text"); textAttr.Value = nt.Name; eleOutline.SetAttributeNode(textAttr); XmlAttribute titleAttr = xdoc.CreateAttribute("title"); titleAttr.Value = nt.Name; eleOutline.SetAttributeNode(titleAttr); ProcessNodeFolderChild((nt as NodeFolder), xdoc, eleOutline); } } return(xdoc); }