我需要帮助进行xpath查询,以提取以下rss结果中每个条目的标题文本和缩略图url
<?xml version='1.0' encoding='UTF-8'?>
<feed xmlns='http://www.w3.org/2005/Atom' xmlns:media='http://search.yahoo.com/mrss/'>
<entry>
<title>LiveFit Augusta - "Gym Time"</title>
<media:group>
<media:thumbnail url='http://i.ytimg.com/vi/Ig7CcLCR2n4/default.jpg'/>
<media:thumbnail url='http://i.ytimg.com/vi/Ig7CcLCR2n4/mqdefault.jpg'/>
<media:thumbnail url='http://i.ytimg.com/vi/Ig7CcLCR2n4/hqdefault.jpg'/>
<media:thumbnail url='http://i.ytimg.com/vi/Ig7CcLCR2n4/1.jpg'/>
<media:thumbnail url='http://i.ytimg.com/vi/Ig7CcLCR2n4/2.jpg'/>
<media:thumbnail url='http://i.ytimg.com/vi/Ig7CcLCR2n4/3.jpg'/>
</media:group>
</entry>
<entry>
<title>LiveFit Augusta - "Everyday Joes & Janes"</title>
<media:group>
<media:thumbnail url='http://i.ytimg.com/vi/REhn9jjjV7Q/default.jpg'/>
<media:thumbnail url='http://i.ytimg.com/vi/REhn9jjjV7Q/mqdefault.jpg'/>
<media:thumbnail url='http://i.ytimg.com/vi/REhn9jjjV7Q/hqdefault.jpg'/>
<media:thumbnail url='http://i.ytimg.com/vi/REhn9jjjV7Q/1.jpg'/>
<media:thumbnail url='http://i.ytimg.com/vi/REhn9jjjV7Q/2.jpg'/>
<media:thumbnail url='http://i.ytimg.com/vi/REhn9jjjV7Q/3.jpg'/>
</media:group>
</entry>
</feed>
标题
<title type='text'>舞蹈的演变<title>
或
<媒体:title type='plain'>舞蹈的进化<媒体:标题>
缩略图
<media:thumbnail
url='http://img.youtube.com/vi/dMH0bHeiRNg/1.jpg' height='97' width='130'
time='00:01:30'/>
编辑
这是我使用的代码
Dim xmlDoc As MSXML2.DOMDocument30
Dim xmlNode As MSXML2.IXMLDOMNode
Dim xmlEntryNodes As IXMLDOMNodeList
Dim ns As String
Set xmlDoc = New DOMDocument30
ns = "xmlns:x='http://www.w3.org/2005/Atom' xmlns:media='http://search.yahoo.com/mrss/'"
xmlDoc.setProperty "SelectionLanguage", "XPath"
xmlDoc.setProperty "SelectionNamespaces", ns
If xmlDoc.loadXML(xmlText) = False Then
Exit Function
End If
Set xmlEntryNodes = xmlDoc.documentElement.selectNodes("/feed/entry")
debug.print xmlEntryNodes.Length返回0
使用:
ns="xmlns:x='http://www.w3.org/2005/Atom'xmlns:media='http://search.yahoo.com/mrss/'"
doc.SetProperty("SelectionNamespaces",ns)
然后使用如下XPath表达式:
/*/x:entry/x:title[. = 'Evolution of Dance']
和这个:
/*/x:entry/media:group/media:thumbnail[@url='http://img.youtube.com/vi/dMH0bHeiRNg/1.jpg']
在此处了解有关SetProperty()
功能的更多信息:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms756048(v=vs.85).aspx
或者,如果您不想注册命名空间,您可以使用可读性较差的表达式,如以下:
/*/*[name()='entry']/*[name()='title'][. = 'Evolution of Dance']
和这个:
/*/*[name()='entry']
/*[name()='media:group']
/*[name()='media:thumbnail']
[@url='http://img.youtube.com/vi/dMH0bHeiRNg/1.jpg']
这就是您想要的吗?
标题
/feed/entry/title
媒体:标题
/feed/entry/media:group/media:title
缩略图
/feed/entry/media:group/media:thumbnail