我可以使用HTML敏捷包呢?可以使用、敏捷、HTML

2023-09-03 03:38:04 作者:此处省略一千字…

我找不到他们的网站上的任何教程。我想知道我可以使用HTML敏捷性包,并用它来分析一个字符串?

I could not find any tutorials on their site. I am wondering can I use Html Agility Pack and use it to parse a string?

就像说我有

string = "<b>Some code </b>

我可以用敏捷包摆脱&LT的; B&GT; 标签?所有我迄今看到的例子已经加载HTML文档一样。

could I use agility pack to get rid of the <b> tags? All the examples I seen so far have been loading like html documents.

推荐答案

如果它是HTML然后肯定的。

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> element
HtmlNode bNode = doc.DocumentNode.SelectSingleNode("b[1]");
string boldText = bNode.InnerText;