0

如何从此文本中获取 List():

For the iPhone do the following:<ul><li>Go to AppStore</li><li>Search by him</li><li>Download</li></ul>

应该包括:去 AppStore,由他搜索,下载

4

2 回答 2

5

将字符串加载到HTML Agility Pack中,然后选择所有li元素内部文本。

HtmlDocument doc = new HtmlDocument();
doc.LoadHtml("following:<ul><li>Go to AppStore</li><li>Search by him</li><li>Download</li></ul>");

var uls = doc.DocumentNode.Descendants("li").Select(d => d.InnerText);
foreach (var ul in uls)
{
    Console.WriteLine(ul);
}
于 2012-05-11T14:36:36.433 回答
2

包装一个 XML 根元素并使用 LINQ to XML:

var xml = "For the iPhone do the following:<ul><li>Go to AppStore</li><li>Search by him</li><li>Download</li></ul>";
xml = "<r>"+xml+"</r>"; 
var ele = XElement.Parse(xml);  
var lists = ele.Descendants("li").Select(e => e.Value).ToList();

返回lists

Go to AppStore 
Search by him 
Download
于 2012-05-11T14:38:04.123 回答