[英]How do I select XML elements in this situation in VB.net?
所以我有:
<rss version="2.0">
<channel>
<title>My channel</title>
<item></item>
<item></item>
<item></item>
<item></item>
</channel>
</rss>
當我使用xmlDocument來解析它時,我嘗試獲取所有項元素,但是如果我使用的話
For Each item As System.Xml.XmlElement In xmlDocument.Item("rss").Item("channel")
它會給我5個而不是4個結果,因為<title>My Channel</title>
被認為是頻道下的項目之一。 我只是想知道是否還有循環只有4項元素。 謝謝!
您可以使用XPath表達式直接向下鑽取所需的元素。 在你的情況下,它將是:
For Each item As System.Xml.XmlElement In XmlDocument.SelectNodes("/rss/channel/item")
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.