Exemple #1
0
        private static List <string> GetTagsFromPostContent(HtmlDocument doc)
        {
            // Parse tags from the content of a blog post that contains HTML
            // similar to the following:
            //
            //    <h3>
            //      Tags</h3>
            //    <ul>
            //      <li><a href="..." rel="tag">    My
            //        System    </a></li>
            //      <li><a href="..." rel="tag">Toolbox</a></li>
            //    </ul>
            //
            // For the example HTML above, a list containing "My System" and
            // "Toolbox" would be returned.

            var tagLinks = doc.DocumentNode.SelectNodes(
                "//h3[normalize-space() = 'Tags']/following-sibling::ul/li/a");

            var tags = new List <string>();

            if (tagLinks != null)
            {
                foreach (var tagLink in tagLinks)
                {
                    var tag = HtmlDocumentHelper.NormalizeWhitespace(
                        tagLink.InnerText).Trim();

                    tags.Add(tag);
                }
            }

            return(tags);
        }