[英]How do I select XML elements in this situation in VB.net?
So I have: 所以我有:
<rss version="2.0">
<channel>
<title>My channel</title>
<item></item>
<item></item>
<item></item>
<item></item>
</channel>
</rss>
When I use xmlDocument to parse it, I try to get all the item elements, but if I use 当我使用xmlDocument来解析它时,我尝试获取所有项元素,但是如果我使用的话
For Each item As System.Xml.XmlElement In xmlDocument.Item("rss").Item("channel")
It would give me 5 instead 4 results, since <title>My Channel</title>
is considered one of the item under channel. 它会给我5个而不是4个结果,因为
<title>My Channel</title>
被认为是频道下的项目之一。 I'm just wondering if there is anyway to loop through only the 4 item elements. 我只是想知道是否还有循环只有4项元素。 Thanks!
谢谢!
You can use XPath expression to drilldown directly to elements you need. 您可以使用XPath表达式直接向下钻取所需的元素。 In your case it would be:
在你的情况下,它将是:
For Each item As System.Xml.XmlElement In XmlDocument.SelectNodes("/rss/channel/item")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.