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

文字列をHTMLAgilityPackにロードしてから、すべて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ルート要素でラップし、LINQtoXMLを使用します。

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 に答える