当前位置: 首页>>代码示例>>C#>>正文


C# HtmlNode.RemoveChild方法代码示例

本文整理汇总了C#中HtmlAgilityPack.HtmlNode.RemoveChild方法的典型用法代码示例。如果您正苦于以下问题:C# HtmlNode.RemoveChild方法的具体用法?C# HtmlNode.RemoveChild怎么用?C# HtmlNode.RemoveChild使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在HtmlAgilityPack.HtmlNode的用法示例。


在下文中一共展示了HtmlNode.RemoveChild方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: RemoveChildKeepGrandChildren

		public static void RemoveChildKeepGrandChildren ( HtmlNode parent , HtmlNode oldChild )
		{
			if ( oldChild.ChildNodes != null )
			{
				HtmlNode previousSibling = oldChild.PreviousSibling;
				foreach ( HtmlNode newChild in oldChild.ChildNodes )
				{
					parent.InsertAfter ( newChild , previousSibling );
					previousSibling = newChild;  // Missing line in HtmlAgilityPack
				}
			}
			parent.RemoveChild ( oldChild );
		}
开发者ID:tranchikhang,项目名称:Voz,代码行数:13,代码来源:HAP.cs

示例2: CleanupHtmlNode

        static HtmlNode CleanupHtmlNode(HtmlNode node)
        {
            Contract.Requires(node != null);
            Contract.Requires(Contract.Result<HtmlNode>() != null);

            foreach(var langSpan in node.ChildNodes.Where(n => n.Name == "span" && n.Attributes.Contains("lang")).ToList()) {
                langSpan.ReplaceWithChildNodes();
            }
            foreach(var fontChildNode in node.ChildNodes.Where(n => n.Name == "font").ToList()) {
                var replacingNode = node.OwnerDocument.CreateElement("span");
                replacingNode.Attributes.Add("class", "terminal-symbol");
                replacingNode.InnerHtml = fontChildNode.FirstChild.InnerHtml; // the font node is doubled
                node.ChildNodes.Insert(node.ChildNodes.GetNodeIndex(fontChildNode), replacingNode);
                node.RemoveChild(fontChildNode);
            }
            var ellipsises = new List<string> { "&hellip;", "..." };
            foreach(var ellipsisLineNode in node.ChildNodes.Where(n => ellipsises.Contains(n.InnerText.Trim()) || n.Name == "br" && ellipsises.Contains(n.PreviousSibling?.InnerText?.Trim())).ToList()) {
                ellipsisLineNode.Remove();
            }
            foreach(var childNode in node.ChildNodes) {
                CleanupHtmlNode(childNode);
            }
            return node;
        }
开发者ID:sirIrishman,项目名称:CSharpGrammarProductionsVisualizer,代码行数:24,代码来源:Program.cs

示例3: recursiveValidateTag

        private void recursiveValidateTag(HtmlNode node)
        {
            int maxinputsize = int.Parse(policy.getDirective("maxInputSize"));

            num++;

            HtmlNode parentNode = node.ParentNode;
            HtmlNode tmp = null;
            string tagName = node.Name;

            //check this out
            //might not be robust enough
            if (tagName.ToLower().Equals("#text"))  // || tagName.ToLower().Equals("#comment"))
            {
                return;
            }

            Tag tag = policy.getTagByName(tagName.ToLower());

            if (tag == null || "filter".Equals(tag.Action))
            {
                StringBuilder errBuff = new StringBuilder();
                if (tagName == null || tagName.Trim().Equals(""))
                    errBuff.Append("An unprocessable ");
                else
                    errBuff.Append("The <b>" + HTMLEntityEncoder.htmlEntityEncode(tagName.ToLower()) + "</b> ");

                errBuff.Append("tag has been filtered for security reasons. The contents of the tag will ");
                errBuff.Append("remain in place.");

                errorMessages.Add(errBuff.ToString());

                for (int i = 0; i < node.ChildNodes.Count; i++)
                {
                    tmp = node.ChildNodes[i];
                    recursiveValidateTag(tmp);

                    if (tmp.ParentNode == null)
                    {
                        i--;
                    }
                }
                promoteChildren(node);
                return;
            }
            else if ("validate".Equals(tag.Action))
            {
                if ("style".Equals(tagName.ToLower()) && policy.getTagByName("style") != null)
                {
                    CssScanner styleScanner = new CssScanner(policy);
                    try
                    {

                        CleanResults cr = styleScanner.scanStyleSheet(node.FirstChild.InnerHtml, maxinputsize);

                        foreach (string msg in cr.getErrorMessages())
                            errorMessages.Add(msg.ToString());

                        /*
                         * If IE gets an empty style tag, i.e. <style/>
                         * it will break all CSS on the page. I wish I
                         * was kidding. So, if after validation no CSS
                         * properties are left, we would normally be left
                         * with an empty style tag and break all CSS. To
                         * prevent that, we have this check.
                         */

                        if (cr.getCleanHTML() == null || cr.getCleanHTML().Equals(""))
                        {

                            //node.getFirstChild().setNodeValue("/* */");
                            node.FirstChild.InnerHtml = "/* */";


                        }
                        else
                        {

                            //node.getFirstChild().setNodeValue(cr.getCleanHTML());
                            node.FirstChild.InnerHtml = cr.getCleanHTML();
                        }

                    }
                    //    catch (DomException e)
                    //    {
                    //        addError(ErrorMessageUtil.ERROR_CSS_TAG_MALFORMED, new Object[] { HTMLEntityEncoder.htmlEntityEncode(node.getFirstChild().getNodeValue()) });
                    //        parentNode.removeChild(node);
                    //    }
                    catch (ScanException e)
                    {
                        Console.WriteLine("Scan Exception: " + e.Message);
                        
                        //addError(ErrorMessageUtil.ERROR_CSS_TAG_MALFORMED, new Object[] { HTMLEntityEncoder.htmlEntityEncode(node.getFirstChild().getNodeValue()) });
                        parentNode.RemoveChild(node);
                    }
                }

                HtmlAttribute attribute = null;
                for (int currentAttributeIndex = 0; currentAttributeIndex < node.Attributes.Count; currentAttributeIndex++)
                {
//.........这里部分代码省略.........
开发者ID:carriercomm,项目名称:web-security,代码行数:101,代码来源:AntiSamyDOMScanner.cs

示例4: promoteChildren

        private void promoteChildren(HtmlNode node)
        {

            HtmlNodeCollection nodeList = node.ChildNodes;
            HtmlNode parent = node.ParentNode;

            while (nodeList.Count > 0)
            {
                HtmlNode removeNode = node.RemoveChild(nodeList[0]);
                parent.InsertBefore(removeNode, node);
            }

            parent.RemoveChild(node);
        }
开发者ID:carriercomm,项目名称:web-security,代码行数:14,代码来源:AntiSamyDOMScanner.cs

示例5: RemoveSubHtmlNode

        public static void RemoveSubHtmlNode(HtmlNode curHtmlNode, string subNodeToRemove)
        {
            try
            {
                var foundAllSub = curHtmlNode.SelectNodes(subNodeToRemove);
                if (foundAllSub != null)
                {
                    foreach (HtmlNode subNode in foundAllSub)
                    {
                        curHtmlNode.RemoveChild(subNode);
                    }
                }
            }
            catch (Exception ex)
            {

                throw ex;
            }

            //return curHtmlNode;
        }
开发者ID:rngmontoli,项目名称:CSNovelCrawler,代码行数:21,代码来源:Network.cs

示例6: ClearNodes

        private static HtmlNode ClearNodes(HtmlNode JobOfferElement)
        {
            //var trsToRemove = JobOfferElement.Elements("tr").ToList();

            //JobOfferElement.RemoveChild(trsToRemove[0]);
            //JobOfferElement.RemoveChild(trsToRemove[1]);
            //JobOfferElement.RemoveChild(trsToRemove[2]);

            JobOfferElement = RemoveDescendants(JobOfferElement, new string[] { "a", "img", "script", "style" });
            JobOfferElement.RemoveChild(JobOfferElement.Element("tr"));

            var trS = JobOfferElement.Elements("tr").ToList();

            bool removeNext = false;
            foreach (var item in trS)
            {
                if (removeNext == false)
                {
                    if (item.Descendants().Where(
                        d => (d.Attributes.Contains("class") &&
                            d.Attributes["class"].Value.Contains("button_new"))
                            ).Count() > 0)
                    {
                        removeNext = true;
                    }
                }
                if (removeNext == true)
                {
                    JobOfferElement.RemoveChild(item);
                }
            }

            return JobOfferElement;
        }
开发者ID:kirotab,项目名称:JobsMatch,代码行数:34,代码来源:RemoteDataManager.cs

示例7: TruncateAction

 /// <summary>
 /// 删除所有的属性和子元素,但保留文本和备注节点
 /// </summary>
 /// <param name="node"></param>
 void TruncateAction(HtmlNode node)
 {
     HtmlAttributeCollection attrs = node.Attributes;
     while (attrs.Count > 0)
     {
         node.Attributes.Remove(attrs[0].Name);
     }
     HtmlNodeCollection nodes = node.ChildNodes;
     int position = 0;
     while (nodes.Count > position)
     {
         HtmlNode nodeToRemove = nodes[position];
         var type = nodeToRemove.NodeType;
         if (type == HtmlNodeType.Text || type == HtmlNodeType.Comment) { position++; continue; }
         node.RemoveChild(nodeToRemove);
     }
 }
开发者ID:sdgdsffdsfff,项目名称:web-security,代码行数:21,代码来源:HtmlFilter.cs

示例8: PromoteChildren

 /// <summary>
 /// 将指定节点从父节点中移除,但其子节点保留
 /// </summary>
 /// <param name="node"></param>
 void PromoteChildren(HtmlNode node)
 {
     ///过滤子节点
     FiltersTags(node.ChildNodes);
     HtmlNodeCollection nodeList = node.ChildNodes;
     HtmlNode parent = node.ParentNode;
     ///将它的所有子节点往上移到父节点的前面
     while (nodeList.Count > 0)
     {
         HtmlNode removeNode = node.RemoveChild(nodeList[0]);
         parent.InsertBefore(removeNode, node);
     }
     //然后将节点删除
     parent.RemoveChild(node);
 }
开发者ID:sdgdsffdsfff,项目名称:web-security,代码行数:19,代码来源:HtmlFilter.cs

示例9: removeSubHtmlNode

    //remove sub node from current html node
    //eg: 
    //"script"
    //for
    //<script type="text/javascript"> 
    public HtmlNode removeSubHtmlNode(HtmlNode curHtmlNode, string subNodeToRemove)
    {
        HtmlNode afterRemoved = curHtmlNode;
        
        ////method 1: fail
        ////foreach (var subNode in afterRemoved.Descendants(subNodeToRemove))
        //foreach (HtmlNode subNode in afterRemoved.Descendants(subNodeToRemove))
        //{
        //    //An unhandled exception of type 'System.InvalidOperationException' occurred in mscorlib.dll
        //    //Additional information: Collection was modified; enumeration operation may not execute.
            
        //    //afterRemoved.RemoveChild(subNode);
        //    //curHtmlNode.RemoveChild(subNode);
        //    subNode.Remove();
        //}

        //method 2: OK
        HtmlNodeCollection foundAllSub = curHtmlNode.SelectNodes(subNodeToRemove);
        if ((foundAllSub != null) && (foundAllSub.Count > 0))
        {
            foreach (HtmlNode subNode in foundAllSub)
            {
                curHtmlNode.RemoveChild(subNode);
            }
        }

        return afterRemoved;
    }
开发者ID:caozq19,项目名称:crifanLib,代码行数:33,代码来源:crifanLib.cs

示例10: ExtractHolidayFromNode

        private static Entry ExtractHolidayFromNode(HtmlNode node)
        {
            var entry = new Entry();
            entry.Links = ExtractAllLinksFromHtmlNode(node);
            entry.Link = ExtractFirstLink(node, entry);

            // put sublists into a description
            if (node.HasChildNodes)
            {
                // TODO: redo this as node parsing
                HtmlNode extraListNode = node.Descendants("ul").FirstOrDefault();
                if (extraListNode != null)
                {
                    entry.Description = HttpUtility.HtmlDecode(extraListNode.InnerText).Trim();
                    node.RemoveChild(extraListNode);
                }
            }

            entry.Year = HttpUtility.HtmlDecode(node.InnerText.Trim().TrimEnd(':'));

            return entry;
        }
开发者ID:camradal,项目名称:OnThisDayApp,代码行数:22,代码来源:PageParser.cs

示例11: KillElems

 void KillElems(HtmlNode n)
 {
     var cs = n.ChildNodes.Cast<HtmlNode> ().ToArray ();
     foreach (var c in cs) {
         var name = c.Name.ToLowerInvariant ();
         if (name == "input" || name == "textarea" || name == "button" || name == "script" || name == "form") {
             n.RemoveChild (c);
         } else if (name == "a") {
             var href = c.Attributes["href"];
             if (href == null || !href.Value.StartsWith ("http")) {
                 n.RemoveChild (c);
             }
         }
     }
     foreach (var c in n.ChildNodes) {
         KillElems (c);
     }
 }
开发者ID:jorik041,项目名称:lcars,代码行数:18,代码来源:MessageReader.xib.cs


注:本文中的HtmlAgilityPack.HtmlNode.RemoveChild方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。