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


C# HtmlNodeCollection.Append方法代码示例

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


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

示例1: ProcessFile

        /// <summary>
        /// Processes the file by updating file text.
        /// </summary>
        public void ProcessFile()
        {
            var pageBody = Html.DocumentNode.SelectSingleNode("//body");
            var newDocNodes = new HtmlNodeCollection(pageBody);

            // Set white background for body.
            pageBody.Attributes.Add("style", "background-color:#fff;");

            // Process stories.
            var stories = pageBody.SelectNodes("table[@class='tableBorder']");
            foreach (var story in stories)
            {
                story.Attributes.Add("style", string.Format("font-size:{0}pt;", StoryTextFontSize));
                var storyBody = story.SelectSingleNode("tbody") ?? story;

                // Story header.
                var header = storyBody.SelectSingleNode("tr");
                var headerCell = header.SelectSingleNode("td");
                headerCell.Attributes["colspan"].Value = "4";
                headerCell.Attributes.Add("style", string.Format("font-size:{0}pt;", StoryHeaderFontSize));
                headerCell.SelectSingleNode("h3").Attributes.Remove("class");
                headerCell.SelectSingleNode("h3/span").Remove();

                storyBody.RemoveAllChildren();
                storyBody.AppendChild(header);

                // Story details.
                var details1 = story.SelectSingleNode("following-sibling::table[1]/tbody") ??
                               story.SelectSingleNode("following-sibling::table[1]");
                var reporter = details1.SelectSingleNode("tr[contains(., 'Reporter')]");
                var estimate = details1.SelectSingleNode("tr[contains(., 'Original Estimate')]");

                if (reporter != null)
                {
                    reporter.InnerHtml = reporter.InnerHtml.Replace("Unassigned", string.Empty);
                    storyBody.AppendChild(reporter);
                }

                if (estimate != null)
                {
                    estimate.InnerHtml = estimate.InnerHtml.Replace("Not Specified", string.Empty);
                    estimate.InnerHtml = estimate.InnerHtml.Replace("Original ", string.Empty);
                    storyBody.AppendChild(estimate);
                }

                var details2 = story.SelectSingleNode("following-sibling::table[2]/tbody") ??
                               story.SelectSingleNode("following-sibling::table[2]");
                var themes = details2.SelectSingleNode("tr[contains(., 'Theme/s')]");
                var acceptanceCriteria = details2.SelectSingleNode("tr[contains(., 'Acceptance Criteria')]");

                if (themes != null)
                {
                    themes.SelectSingleNode("td[2]").Attributes.Add("colspan", "3");
                    storyBody.AppendChild(themes);
                }

                if (acceptanceCriteria != null)
                {
                    acceptanceCriteria.SelectSingleNode("td[1]").Attributes["bgcolor"].Remove();
                    acceptanceCriteria.SelectSingleNode("td[2]").Attributes.Add("colspan", "3");
                    storyBody.AppendChild(acceptanceCriteria);
                }

                // Set previous element to find optional description and comments tables.
                var previousElement = details2.Name == "table" ? details2 : details2.ParentNode;

                // Description.
                var descriptionHeader = previousElement.SelectSingleNode("following-sibling::table[1]/tbody/tr/td") ??
                                        previousElement.SelectSingleNode("following-sibling::table[1]/tr/td");
                if (descriptionHeader != null && descriptionHeader.InnerText.Trim() == "&nbsp;Description&nbsp;")
                {
                    previousElement = previousElement.SelectSingleNode("following-sibling::table[2]");
                    var description = previousElement.SelectSingleNode("tbody/tr/td") ??
                                      previousElement.SelectSingleNode("tr/td");
                    description.Attributes.Remove("id");
                    description.Attributes.Add("colspan", "4");
                    storyBody.AppendChild(description.ParentNode);
                }

                // Comments.
                var commentsHeader = previousElement.SelectSingleNode("following-sibling::table[1]/tbody/tr/td") ??
                                     previousElement.SelectSingleNode("following-sibling::table[1]/tr/td");
                if (commentsHeader != null && commentsHeader.InnerText.Trim() == "&nbsp;Comments&nbsp;")
                {
                    var comments = previousElement.SelectNodes("following-sibling::table[2]/tbody/tr") ??
                                   previousElement.SelectNodes("following-sibling::table[2]/tr");
                    foreach (var comment in comments)
                    {
                        if (comment.Attributes["id"].Value.StartsWith("comment-header"))
                        {
                            comment.SelectSingleNode("td/font").Remove();
                        }

                        comment.SelectSingleNode("td").Attributes.Add("colspan", "4");
                        comment.Attributes.Add("style", string.Format("font-size:{0}pt;", CommentsTextFontSize));
                    }

//.........这里部分代码省略.........
开发者ID:kirmir,项目名称:JiraStoryPrint,代码行数:101,代码来源:JiraStoryUpdater.cs

示例2: FilterCanvasOutput

    public string FilterCanvasOutput(string canvas_output)
    {
        try
        {
            HtmlDocument htmlDoc = new HtmlDocument();
            htmlDoc.LoadHtml(UnescapeXml(canvas_output));
            StringBuilder clean_html = new StringBuilder();
            HtmlNodeCollection list = htmlDoc.DocumentNode.SelectNodes("//div[@title]");
            if (list == null)
                return "";
            foreach (HtmlNode node in list)
            {
                //remove incidental divs
                HtmlNodeCollection bad_nodes = new HtmlNodeCollection(node);
                foreach (HtmlNode child in node.ChildNodes)
                {
                    if (child.Name == "div" && child.Attributes["class"] != null && child.Attributes["class"].Value.Contains("resizable"))
                        bad_nodes.Append(child);
                }
                for (int i = 0; i < bad_nodes.Count; i++)
                {
                    bad_nodes[i].Remove();
                }

                clean_html.Append(node.OuterHtml);
            }
            return clean_html.ToString();
        }
        catch (Exception ex)
        {
            throw new Exception(ex.Message + ": " + ex.StackTrace);
        }
    }
开发者ID:dcolonvizi,项目名称:ViziAppsPortal,代码行数:33,代码来源:XmlUtil.cs


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