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


C# HtmlNode.Remove方法代码示例

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


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

示例1: SanitizeHtmlNode

        private void SanitizeHtmlNode(HtmlNode node)
        {
            if (node.NodeType == HtmlNodeType.Element)
            {
                // check for blacklist items and remove
                if (BlackList.Contains(node.Name))
                {
                    node.Remove();
                    return;
                }

                // remove CSS Expressions and embedded script links
                if (node.Name == "style")
                {
                    if (string.IsNullOrEmpty(node.InnerText))
                    {
                        if (node.InnerHtml.Contains("expression") || node.InnerHtml.Contains("javascript:"))
                            node.ParentNode.RemoveChild(node);
                    }
                }

                // remove script attributes
                if (node.HasAttributes)
                {
                    for (int i = node.Attributes.Count - 1; i >= 0; i--)
                    {
                        HtmlAttribute currentAttribute = node.Attributes[i];

                        var attr = currentAttribute.Name.ToLower();
                        var val = currentAttribute.Value.ToLower();

                        //span style="background: white; color: green"> remove event handlers
                        if (attr.StartsWith("on"))
                            node.Attributes.Remove(currentAttribute);

                        // remove script links
                        else if (
                                 //(attr == "href" || attr== "src" || attr == "dynsrc" || attr == "lowsrc") &&
                                 val != null &&
                                 val.Contains("javascript:"))
                            node.Attributes.Remove(currentAttribute);

                        // Remove CSS Expressions
                        else if (attr == "style" &&
                                 val != null &&
                                 val.Contains("expression") || val.Contains("javascript:") || val.Contains("vbscript:"))
                            node.Attributes.Remove(currentAttribute);
                    }
                }
            }

            // Look through child nodes recursively
            if (node.HasChildNodes)
            {
                for (int i = node.ChildNodes.Count - 1; i >= 0; i--)
                {
                    SanitizeHtmlNode(node.ChildNodes[i]);
                }
            }
        }
开发者ID:pavelsavrovsky,项目名称:cactus,代码行数:60,代码来源:HtmlSanitizer.cs

示例2: RemoveComments

 public static HtmlNode RemoveComments(HtmlNode node)
 {
     foreach (var n in node.ChildNodes.ToArray())
         RemoveComments(n);
     if (node.NodeType == HtmlNodeType.Comment)
         node.Remove();
     return node;
 }
开发者ID:dnmsk,项目名称:rProject,代码行数:8,代码来源:HtmlBlockHelper.cs

示例3: SimplifyKoTag

 /// <summary>
 /// Converts ko tag into a ko comment (virtual element) if bindings still exist; otherwise,
 /// removes the tag entirely, but preserves the child nodes in the process.
 /// </summary>
 /// <param name="node">The ko element.</param>
 private static void SimplifyKoTag(HtmlNode node)
 {
     if (node.Name != "ko") return;
     var parentNode = node.ParentNode;
     if (node.HasAttributes)
         parentNode.InsertBefore(HtmlNode.CreateNode(
             string.Format("<!-- ko {0} -->", node.Attributes["data-bind"].Value)), node);
     foreach (var cn in node.ChildNodes)
         parentNode.InsertBefore(cn, node);
     if (node.HasAttributes)
         parentNode.InsertBefore(HtmlNode.CreateNode("<!-- /ko -->"), node);
     node.Remove();
 }
开发者ID:jedmao,项目名称:knockout-viewengine,代码行数:18,代码来源:BoundView.cs

示例4: SanitizeNode

 private static void SanitizeNode(HtmlNode node)
 {
     if (node.NodeType == HtmlNodeType.Element)
     {
         // TODO: whitelist?
         node.Remove();
         return;
     }
     if (node.HasChildNodes)
     {
         for (int i = node.ChildNodes.Count - 1; i >= 0; i--)
         {
             SanitizeNode(node.ChildNodes[i]);
         }
     }
 }
开发者ID:jdaigle,项目名称:CommentR,代码行数:16,代码来源:Util.cs

示例5: SanitizeHtmlNode

        private void SanitizeHtmlNode(HtmlNode node)
        {
            if (node.NodeType == HtmlNodeType.Element)
            {
                // check for WhiteList items and remove
                if (!WhiteList.Contains(node.Name))
                {
                    node.Remove();
                    return;
                }

                // remove CSS Expressions and embedded script links
                if (node.Name == "style")
                {
                    var val = node.InnerHtml;
                    if (string.IsNullOrEmpty(node.InnerText))
                    {
                        if (HasExpressionLinks(val) || HasScriptLinks(val) )
                            node.ParentNode.RemoveChild(node);
                    }
                }

                // remove script attributes
                if (node.HasAttributes)
                {
                    for (int i = node.Attributes.Count - 1; i >= 0; i--)
                    {
                        HtmlAttribute currentAttribute = node.Attributes[i];

                        var attr = currentAttribute.Name.ToLower();
                        var val = currentAttribute.Value.ToLower();

                        // remove event handlers
                        if (attr.StartsWith("on"))
                        {
                            node.Attributes.Remove(currentAttribute);
                        }
                        // Remove CSS Expressions
                        else if (attr == "style" && val != null && HasExpressionLinks(val) || HasScriptLinks(val))
                        {
                            node.Attributes.Remove(currentAttribute);
                        }
                        // remove script links from all attributes
                        else if (val != null && HasScriptLinks(val))
                        {
                            node.Attributes.Remove(currentAttribute);
                        }
                    }
                }
            }

            // Look through child nodes recursively
            if (node.HasChildNodes)
            {
                for (int i = node.ChildNodes.Count - 1; i >= 0; i--)
                {
                    SanitizeHtmlNode(node.ChildNodes[i]);
                }
            }
        }
开发者ID:Mukesh-Joshi,项目名称:MS-Work,代码行数:60,代码来源:HtmlSanitizer.cs

示例6: RemoveComments

 private void RemoveComments(HtmlNode node)
 {
     if (_removeComments)
     {
         if (node.NodeType == HtmlNodeType.Comment)
         {
             var parentNode = node.ParentNode;
             node.Remove();
             if (parentNode.Attributes.Count == 0 && (parentNode.InnerText == null || parentNode.InnerText == string.Empty))
             {
                 parentNode.Remove();
             }
             return;
         }
     }
 }
开发者ID:hernangm,项目名称:Eqip.Utils.Html,代码行数:16,代码来源:HtmlStringHelper.cs

示例7: NodeProcess

        /// <summary>
        /// Run a process recursively on an HtmlNode and all those it contains
        /// </summary>
        /// <param name="node">The top level HtmlNode</param>
        /// <param name="process">Action on an HtmlNode</param>
        public static void NodeProcess(HtmlNode node, Action<HtmlNode> process)
        {
            if (node.NodeType == HtmlNodeType.Element)
            {
                process(node);
            }
            else if (node.NodeType == HtmlNodeType.Comment)
            {
                node.Remove();
            }

            // Look through child nodes recursively
            if (node.HasChildNodes)
            {
                for (int i = node.ChildNodes.Count - 1; i >= 0; i--)
                {
                    if (i >= node.ChildNodes.Count)
                        i = node.ChildNodes.Count - 1;
                    NodeProcess(node.ChildNodes[i], process);
                }
            }
        }
开发者ID:jamesej,项目名称:lynicon,代码行数:27,代码来源:HtmlX.cs

示例8: RemoveComments

 /// <summary>
 /// 
 /// </summary>
 /// <param name="node"></param>
 public static void RemoveComments(HtmlNode node)
 {
     foreach (var n in node.ChildNodes.ToArray())
     {
         RemoveComments(n);
     }
     if (node.NodeType == HtmlNodeType.Comment)
     {
         node.Remove();
     }
 }
开发者ID:jiangguang5201314,项目名称:DotNetFramework,代码行数:15,代码来源:HtmlAgilityPackHelper.cs

示例9: filterElement

 /// <summary>
 /// Filters the element, returns whether the element was removed.
 /// </summary>
 /// <param name="node"></param>
 /// <returns></returns>
 private bool filterElement(HtmlNode node)
 {
     if (ElementFilter.IsValid(node))
     {
         for(int i = 0; i < node.ChildNodes.Count; i++)
         {
             if (filterElement(node.ChildNodes[i]))
             {
                 i--;
             }
         }
         return false;
     }
     else
     {
         node.RemoveAllChildren();
         node.Remove();
         return true;
     }
 }
开发者ID:KallynGowdy,项目名称:TheFlow,代码行数:25,代码来源:Sanitizer.cs


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