Can I use Html Agility Pack To Parse HTML Fragment?
问题 Can Html Agility Pack be used to parse an html string fragment? Such As: var fragment = "<b>Some code </b>"; Then extract all <b> tags? All the examples I seen so far have been loading like html documents. 回答1: If it's html then yes. string str = "<b>Some code</b>"; // not sure if needed string html = string.Format("<html><head></head><body>{0}</body></html>", str); HtmlDocument doc = new HtmlDocument(); doc.LoadHtml(html); // look xpath tutorials for how to select elements // select 1st <b>